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.
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++
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With