std:thread vs _beginthread, _endthread...

John Hite 41 Reputation points
2021-10-25T00:40:00.587+00:00

I have used threads with other OS's and now I am using Visual Studio 2022 Preview and I am trying to find a document that discusses Windows threads. I can find some functions like _beginthread and _endthread and I have found other scattered documents that say do or don't use CreateThread. Surely there is a better way than jumping from one fn reference page to another and guessing what other functions may cooperate.

Another source of confusion is that in addition to the above functions the compiler also accepts std::thread syntax. So who uses what, when, where, and how?

BTW, I tried to use c++, C++, and threads for tags but none were accepted so I quit out and found a tag someone else had used successfully, vs-debugging.

Thanks,
John

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,518 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Castorix31 81,461 Reputation points
    2021-10-25T06:11:53.473+00:00

    There is in MSDN, at CreateThread function :

    "
    A thread in an executable that calls the C run-time library (CRT) should use the _beginthreadex and _endthreadex functions for thread management rather than CreateThread and ExitThread; this requires the use of the multithreaded version of the CRT. If a thread created using CreateThread calls the CRT, the CRT may terminate the process in low-memory conditions.
    "

    0 comments No comments

  2. Viorel 111.7K Reputation points
    2021-10-25T08:53:30.2+00:00

    I think that you should use std::thread and other classes from STL, because they are designed to take care about different details and initialisations. The implementation uses _beginthreadex internally, which invokes CreateThread (in Windows), according to available sources. The code that uses std::thread will also work in different Operating Systems.

    0 comments No comments