In g++ is C++ 11 thread model using pthreads in the background?(在 g++ 中是在后台使用 pthreads 的 C++ 11 线程模型吗?)
问题描述
我只是在尝试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 线程模型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 g++ 中是在后台使用 pthreads 的 C++ 11 线程模型吗
基础教程推荐
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- CString 到 char* 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
