Gordon
Gordon

Reputation: 446

Does C++11 thread library call OS API to run multi-thread program?

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

Answers (2)

Zan Lynx
Zan Lynx

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

spectras
spectras

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

Related Questions