c++ - std::thread 错误(线程不是 std 的成员)

标签 c++ multithreading gcc c++11 std

我使用 macports 编译并安装了 gcc4.4。

当我尝试使用 -> g++ -g -Wall -ansi -pthread -std=c++0x main.cpp...进行编译时...:

 #include <thread>
 ...
  std::thread t(handle);
  t.join();
 ....

编译器返回:

 cserver.cpp: In member function 'int CServer::run()':
 cserver.cpp:48: error: 'thread' is not a member of 'std'
 cserver.cpp:48: error: expected ';' before 't'
 cserver.cpp:49: error: 't' was not declared in this scope

但是std::cout <<...编译正常..

谁能帮帮我?

最佳答案

gcc 还不完全支持 std::thread:

http://gcc.gnu.org/projects/cxx0x.html

http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html

使用 boost::thread同时。

编辑

尽管使用 gcc 4.4.3 对我来说以下编译并运行良好:

#include <thread>
#include <iostream>

struct F
{
  void operator() () const
  {
    std::cout<<"Printing from another thread"<<std::endl;
  }
};

int main()
{
  F f;
  std::thread t(f);
  t.join();

  return 0;
}

编译

g++ -Wall -g -std=c++0x -pthread main.cpp

a.out 的输出:

Printing from another thread

你能提供完整的代码吗?也许在那些 ... 中潜伏着一些不为人知的问题?

关于c++ - std::thread 错误(线程不是 std 的成员),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2519607/

相关文章:

c++ - 在 C++ 中获取字符串的特殊部分

c++ - atexit() 函数仿生与 glibc

GCC:为 ARM 构建交叉编译器 - 未找到 pthread.h

c - 为什么编译器会在编译的汇编代码中生成额外的 sqrts

linux - 无法编译包含 <linux/leds.h> 的 C 程序

c++ - 如何比较 std::map 中的所有项目?

C++在linux下启动新进程并终止当前进程

c++ - 无法将套接字对象移动到 std::vector

java - Java 并发的困难时期

multithreading - JavaFX 应用程序线程如何工作?