Windows 上的 C++11 线程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6783512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C++11 threading on Windows
提问by csteifel
Is there anyway to use std::thread
with C++11 standard library in windows when compiling with g++ 4.5.2 in MinGW?
std::thread
在 MinGW 中使用 g++ 4.5.2 编译时,是否可以在 Windows 中使用C++11 标准库?
I'm going assume no as I've seen many things saying you have to compile with the pthreads option but I figure I'd ask anyway.
我会假设没有,因为我已经看到很多事情说你必须使用 pthreads 选项进行编译,但我想我还是会问。
回答by rubenvb
There is experimental support for std::thread
in for MinGW-w64 toolchains.
有std::thread
对 MinGW-w64 工具链的实验性支持。
Specifically, my GCC 4.6 builds provide usable std::thread
through MinGW-w64's winpthreads library.
具体来说,我的 GCC 4.6 版本std::thread
通过 MinGW-w64 的 winpthreads 库提供可用。
You can find downloads here:
你可以在这里找到下载:
Apart from that, MSVC11 (Visual Studio 2012) has <thread>
, <chrono>
, and <atomic>
. You can download the Express edition here.
除此之外,MSVC11(的Visual Studio 2012)有<thread>
,<chrono>
和<atomic>
。您可以在此处下载 Express 版。
回答by Alexander Vassilev
There is already a lightweight native implementation of std::thread and sync primitives: https://github.com/meganz/mingw-std-threads
已经有 std::thread 和同步原语的轻量级本地实现:https: //github.com/meganz/mingw-std-threads
IT is a header-only library and should work with any C++11 compliant version of MinGW. You just need to include the headers in your code.
IT 是一个仅限头文件的库,应该与任何 C++11 兼容版本的 MinGW 一起使用。您只需要在代码中包含标题。