Loo*_*oom 22 c++ concurrency gcc mingw c++11
在尝试编译以下代码时
#include <thread>
#include <iostream>
void foo() { std::cout << "foo\n"; }
int main()
{
std::thread t(foo);
t.join();
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
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
Run Code Online (Sandbox Code Playgroud)
如何使用C++ 11实验并发功能?我有MinGW GCC 4.5.1(TDM)
编辑: BTW,Visual Studio 2012执行良好的代码示例.
blu*_*rni 14
据我所知,MinGW还不支持新的c ++ 0x并发功能(从GCC 4.5开始).我记得读过一个邮件列表交换,其中指出在MinGW中,以下来自线程头的ifdef不满足:
#if defined(_GLIBCXX_HAS_GTHREADS)
Run Code Online (Sandbox Code Playgroud)
我想这与MinGW在Windows下构建的方式有关,无论是使用本机线程还是pthread等.在我的代码中,我编写了一些使用Boost.thread而不是本机c ++ 0x线程的最小包装.在Windows中.这两个接口非常相似,对于许多用途,它们可以毫无问题地进行交换.
编辑:感谢Luc Danton挖掘出上面提到的邮件列表主题:
http://comments.gmane.org/gmane.comp.gnu.mingw.user/33065