Reputation: 446
As we all know,we can use C++ library write general multi-thread code across platform(no matter Linux or Windows),I wondered why c++11 make it simple,does it call OS API actually,or use some other technique?
Upvotes: 1
Views: 284
Reputation: 54345
Yes it does use the OS API. And you have to link the threading libraries when you use C++ threads.
In Linux/Unix pass -pthread
to the compiler. In Visual Studio pick the MT runtime library.
Upvotes: 1
Reputation: 13552
C++ is just a language you used to express your ideas.
In the end, your binary still has to use operating system's features to perform anything that requires system-level access, such as manipulating the system scheduler (eg: creating a thread).
Details of what OS features your compiler and libraries use to support C++ language features can be found in their documentation. I guess most Linux envs use pthread under the hood for C++ threads, and windows ones use win32 apis.
If you use gcc
, you can use gcc -v
to get that information:
spectras@etherbee:~$ g++ -v
…
Thread model: posix
…
That means on my system it uses posix threads.
Upvotes: 2