Linux multithreading would involve the pthreads library(in most cases) . What is the equivalent library used by MSVC?
I need to know which ar开发者_Go百科e the APIs/library used for multithreading by MSVC . If there are more than one , please let me know which is the most widely used.
If my question sounds too naive , its because I've never done threading before , and from my past experience , I know there are people here who can get me started/point me at the right direction , from which point I can start.
Threading on Windows doesn't require any extra library, it's built right into the Win32 API. For example, to create a thread, call CreateThread
. The complete list of threading functions can be found on MSDN at Process and Thread Functions.
Note that if you are writing a program that uses MSVCRT, you may want to call the _beginthread()
family of functions instead. Doing so will help set up and tear down additional data structures used to support threading by the MSVCRT library.
As others have suggested you can use CreateThread or _beginthread or the threadpool APIs, the process and threads reference is best for Win32 threading, you can also use boost::thread which is very close to the C++0x std::thread standard.
The other option if you're using Visual Studio is to take a look at the Parallel Pattern Library and Asynchronous Agents Library which are part of Microsoft's Concurrency Runtime (ConcRT) and are new in Visual Studio 2010. There are several how-to help topics which in the link that can help you get started here.
The API's in ConcRT are 'task' APIs rather than thread APIs and let you work at a slightly higher level of abstraction than threads. i.e. parallel loops, parallel pipelines and groups of tasks. Like boost::thread, the APIs are primarily setup to work with functors rather than the CreateThread / ThreadPool style APIs though there are APIs which are similar syntactically to CreateThread (Concurrency::Scheduler::ScheduleTask for example).
-Rick
As @Greg said you can use CreateThread for creating a thread on windows . Other option is to use boost threads which IMHO provide a much better interface for handling them.
精彩评论