在g ++是C ++ 11线程模型使用pthreads在后台? [英] In g++ is C++ 11 thread model using pthreads in the background?

查看:104
本文介绍了在g ++是C ++ 11线程模型使用pthreads在后台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是试着在 g ++ 4.6 C ++ 11 功能。
每次我编译一个简单的线程代码使用 -std = c ++ 0x 标志,它崩溃与分段错误或它只是抛出一些奇怪的异常。 / p>

我读了一些有关 C ++ 11 线程的问题,我意识到,我还需要使用 -pthread 标志来正确编译代码。使用 -pthread 工作正常,我能够运行线程代码。



我的问题是, code> C ++ 11 多线程模型在后台使用 Pthreads
或者是从头开始写的?



我不知道是否有任何成员 gcc 贡献者,但我只是好奇。

解决方案

如果您运行 g ++ -v 的有关如何配置的信息。其中一个通常是一个看起来像

的线

 线程模型:posix 

这意味着它被配置为使用pthreads作为其线程库(libstdc ++中的std :: thread),这意味着您还需要使用任何您的系统上的pthread可能需要的标志( -pthread 在Linux上)。



做标准,它只是g ++


实现标准的细节

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++

这篇关于在g ++是C ++ 11线程模型使用pthreads在后台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆