question

JohnHite-1908 avatar image
0 Votes"
JohnHite-1908 asked Viorel-1 edited

std:thread vs _beginthread, _endthread...

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++
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Castorix31 avatar image
0 Votes"
Castorix31 answered

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.
"



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
0 Votes"
Viorel-1 answered Viorel-1 edited

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.