相关疑难解决方法(0)

如何在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执行良好的代码示例.

c++ concurrency gcc mingw c++11

22
推荐指数
2
解决办法
2万
查看次数

用g ++编写的线程?

可能重复:
在命名空间std中找不到GCC std :: thread

我希望这个代码在gcc下编译,但它没有.我正在使用mingw 4.7.0.我看到标题,但类似乎不存在.我需要什么旗帜?我跑了

g++ -std=gnu++11 main.cpp
Run Code Online (Sandbox Code Playgroud)

代码

#include<atomic>
#include<thread>
#include<iostream>
using namespace std;
atomic<int> a1,a2,a3;

void test(){
    cout<<"run";
}

int main(){
    thread t(test);
    t.join();
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误是线程不存在.在我的其他代码中它也说std :: this_thread :: yield()不存在.MSVC11编译这个罚款

c++ multithreading gcc mingw

1
推荐指数
1
解决办法
2038
查看次数

标签 统计

c++ ×2

gcc ×2

mingw ×2

c++11 ×1

concurrency ×1

multithreading ×1