问题描述
我只是在尝试g++ 4.6
和C++11
功能.每次我使用 -std=c++0x
标志编译一个简单的线程代码时,它要么因分段错误而崩溃,要么只是抛出一些奇怪的异常.
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.
我阅读了一些与 C++11
线程相关的问题,我意识到,我还需要使用 -pthread
标志来正确编译代码.使用 -pthread
工作正常,我能够运行线程代码.
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.
我的问题是,C++11
多线程模型是否在后台使用Pthreads
?还是从头开始写的?
My question is, whether the C++11
multi-threading model uses Pthreads
in the background?
Or is it written from the scratch?
我不知道是否有任何成员是 gcc
贡献者,但我只是好奇.
I don't know if any of the members are gcc
contributors but I am just curious.
推荐答案
如果你运行 g++ -v
它会给你一堆关于它是如何配置的信息.其中之一通常是一条看起来像
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
这意味着它被配置为将 pthreads 用于其线程库(libstdc++ 中的 std::thread),这意味着您还需要使用系统上 pthreads 可能需要的任何标志(-pthread
在 Linux 上).
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).
这与标准无关,只是g++如何实现标准的细节
This has nothing specific to do with the standard, its just a detail of how the standard is implemented by g++
这篇关于在 g++ 中是在后台使用 pthreads 的 C++ 11 线程模型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!