Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In g++ is C++ 11 thread model using pthreads in the background?

I am just trying my hands on g++ 4.6 and C++11 features. Every time I compile a simple threading code using -std=c++0x flag, either it crashes with segmentation fault or it just throws some weird exception.

I read some questions related to C++11 threads and I realized that, I also need to use -pthread flag to compile the code properly. Using -pthread worked fine and I was able to run the threaded code.

My question is, whether the C++11 multi-threading model uses Pthreads in the background? Or is it written from the scratch?

I don't know if any of the members are gcc contributors but I am just curious.

like image 691
Recker Avatar asked Aug 02 '12 19:08

Recker


1 Answers

If you run g++ -v it will give you a bunch of information about how it was configured. One of those things will generally be a line that looks like

Thread model: posix

which means that it was configured to use pthreads for its threading library (std::thread in libstdc++), and which means you also need to use any flags that might be required for pthreads on your system (-pthread on Linux).

This has nothing specific to do with the standard, its just a detail of how the standard is implemented by g++

like image 23
Chris Dodd Avatar answered Nov 08 '22 07:11

Chris Dodd