Results 1 to 4 of 4

Thread: Questions about Strings and Threads

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,058

    Questions about Strings and Threads

    So I have questions about these 2 separate topics, as they will both be used in the program I'm trying to make.

    Regarding strings, when compiling in MS Visual C++? My copy of MSVC++ has 2 include files for strings. One is called "strings" which internally looks like a ".h" file but has no file extension, and the other is actually called "strings.h" (it has the .h file extension). Which of these 2 header files (or possibly both of them) will I need to make sure my C++ project supports strings properly?

    Regarding threads (created with std::thread, not the Windows API function CreateThread), I want my thread to run independently of the handle it will have (and yes, I know that internally it will use a Windows thread handle, even though this isn't exposed in C++, because any program written in Windows will internally use CreateThread, even if that isn't exposed to the programmer). My program may generate multiple threads, which will need to run independently, and the main thread will have no need to keep track of them (thus no need to keep a bunch of Windows thread handles open). To avoid wasting Windows thread handles, I want to close the thread handle for each thread that is created, as soon as it's created. Does the C++ thread function detach() internally call the Windows function CloseHandle to close the handle for the corresponding Windows thread? Or does detach() only clean up C++ related stuff, while leaving the Windows thread handle open? Will I separately need to find out the actual Windows thread handle embedded in the C++ thread, and then call the Windows API function CloseHandle to actually close the thread's Windows thread handle?

  2. #2
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    734

    Re: Questions about Strings and Threads

    The C++ include file for std::string is string ( no .h) The C++ include file for c-style string functions (strcpy, strcat etc) is cstring (no .h). Also for c-style style string functions string.h can be used for the include file but is not recommended.

    strings and strings.h are not part of the standard c++.

    How the c++ std::thread is implemented is 'implementation defined' and as long as it conforms with the standard can be implemented as the implementers determine. Implementations can vary between versions - so nothing really should be assumed about any implementation.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++20 Compiler: Microsoft VS2019 (16.11.4)

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,058

    Re: Questions about Strings and Threads

    Quote Originally Posted by 2kaud View Post
    The C++ include file for std::string is string ( no .h) The C++ include file for c-style string functions (strcpy, strcat etc) is cstring (no .h). Also for c-style style string functions string.h can be used for the include file but is not recommended.

    strings and strings.h are not part of the standard c++.

    How the c++ std::thread is implemented is 'implementation defined' and as long as it conforms with the standard can be implemented as the implementers determine. Implementations can vary between versions - so nothing really should be assumed about any implementation.
    So then the "strings.h" file is only for use in C, not C++?

    Also, do you have an answer my question about C++ threads?

  4. #4
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    734

    Re: Questions about Strings and Threads

    In C, you use string.h - not strings.h. the include files strings.h and strings are not part of the standard (C or C++). A standard install of c/c++ for MSVS does not have a strings.h file. There is a header-only strings library which is available - but this is a 3rd party add-on to c/c++ and not part of the standard. See https://github.com/win32ports/strings_h

    As I said above, how std::thread is implemented is 'implementation defined'. This can change from one compiler version to the next (and between different compiler vendors) so nothing that isn't part of the C++ standard should be assumed or made use of.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++20 Compiler: Microsoft VS2019 (16.11.4)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width