如何启用MinGW中的实验性C ++ 11并发功能? [英] How to enable experimental C++11 concurrency features in MinGW?

查看:793
本文介绍了如何启用MinGW中的实验性C ++ 11并发功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试编译以下代码时

#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


$ b b

如何使用C ++ 11实验并发功能?我有MinGW GCC 4.5.1(TDM)

How to use C++11 experimental concurrency features? I have MinGW GCC 4.5.1 (TDM)

编辑: 样本。

BTW, Visual Studio 2012 performs good this code sample.

推荐答案

据我所知,MinGW不支持新的c ++ 0x并发功能GCC 4.5)。我记得阅读邮件列表交换,其中指出,在MinGW以下ifdef从线程标题不满足:

To the best of my knowledge, MinGW does not support yet the new c++0x concurrency features (as of GCC 4.5). I remember reading a mailing list exchange in which it was pointed out that in MinGW the following ifdef from the thread header is not satisfied:

#if defined(_GLIBCXX_HAS_GTHREADS)



我想这是某种程度上与MinGW在Windows ,不管它使用本机线程还是pthread等。在我的代码中,我写了一些最小的包装,使用Boost.thread而不是本机c ++ 0x线程在Windows中。这两个界面非常相似,对于许多用途,它们可以互换而没有问题。

I guess this is somehow related to the way MinGW is built under Windows, whether it uses native threads or pthread, etc. In my code, I've written some minimal wrapping that uses Boost.thread instead of native c++0x threads when in Windows. The two interfaces are very similar and for many uses they can be swapped without issues.

EDIT Luc Danton用于挖掘上面提到的邮件列表线程:

EDIT: Thanks to Luc Danton for digging out the mailing list thread mentioned above:

http://comments.gmane.org/gmane.comp.gnu.mingw.user/33065

这篇关于如何启用MinGW中的实验性C ++ 11并发功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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