Visual Studio C++ threads

Greetings,

I have worked with threads using other operating systems but now need to work with threads in Visual Studio. I have installed 2022 Preview.

Is there a unified document that discusses Windows threads that is up to date? I am finding lots of bits and pieces but it is a pain to have to scrounge around in a reference to find a function and then guess what others cooperate with it.

For creating threads I have seen CreateThread, _beginthread, and _beginthreadex. I have seen documentation that says don't use CreateThread but yet on a microsoft page dated 06/18/2021 it recommends CreateThread. Thus a unified description or tutorial would be most useful.

BTW, if using VS 2022 Preview I recommend making copies of your .cpp files in another directory. I had 13 projects and today after an update 5 .cpp files disappeared.

Thanks,
John
Last edited on
I don't know of any such document, but I'm posting to remind you that the C++ standard library has a thread interface (std::thread) and it may be suitable.
Thanks for the note. I was just getting ready to update my post as I just found that the std::thread syntax is accepted. Sometimes Windows has its own, different way but since it supports the standard library one wonders what to do.
it has its own, and it supports p-threads for cross platform (you have to download and so on for that). But neither one make sense now that threads are part of the language; this would only be useful if you had old code that used these things.
I have seen CreateThread, _beginthread, and _beginthreadex.
Never use CreateThread. That's the platform's native thread methods. It doesn't handle per thread instance variables like errno, the time struct tm used by localtime, gmtime, ...

Don't use _beginthread as it doesn't give you the thread handle that you need to close when you're done.

_beginthreadex is the only one you could use, but don't use that either because it's vendor specific.

Don't use pthreads, in this day and age, why would you?

If using C++, use std::thread. If using C, use thrd.
Last edited on
Thanks for all the good info.

Regarding pthreads, I think it has some attributes that std::thread does not have like stack size, priority, scheduling policy, etc. Maybe, but what do I know? I am older than dirt.

Thanks again for the prompt answers,
John
Topic archived. No new replies allowed.