当尝试编译以下代码时
#include <thread>
#include <iostream>
void foo() { std::cout << "foo\n"; }
int main()
{
std::thread t(foo);
t.join();
}
我收到错误:
C:\Test>g++ -g -Wall -lpthread -std=c++0x
main.cpp
main.cpp: In function 'int main()':
main.cpp:12:2: error: 'thread' is not a member of 'std'
main.cpp:12:14: error: expected ';' before 't'
main.cpp:13:2: error: 't' has not been declared
如何使用C++11实验性并发特性?我有 MinGW GCC 4.5.1 (TDM)
EDIT:
据我所知,MinGW 尚不支持新的 c++0x 并发功能(从 GCC 4.5 开始)。我记得读过一个邮件列表交换,其中指出在 MinGW 中,线程头中的以下 ifdef 不满足:
#if defined(_GLIBCXX_HAS_GTHREADS)
我想这在某种程度上与 Windows 下构建 MinGW 的方式有关,无论它使用本机线程还是 pthread 等。在我的代码中,我编写了一些最小包装,在以下情况下使用 Boost.thread 而不是本机 c++0x 线程:在Windows中。这两个接口非常相似,对于许多用途来说,它们可以毫无问题地互换。
EDIT:感谢 Luc Danton 挖掘出上面提到的邮件列表线程:
http://comments.gmane.org/gmane.comp.gnu.mingw.user/33065 http://comments.gmane.org/gmane.comp.gnu.mingw.user/33065
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)