C++11 线程不工作

标签 c++ multithreading gcc c++11

<分区>

我的程序如下所示

#include <iostream>
#include <thread>
#include <exception>

void hello()
{
    std::cout << "Hello world!!!!" << std::endl;
}

int main()
{
    std::cout << "In Main\n";
    std::thread t(hello);
    t.join();
    return 0;
}

当我使用以下命令编译它时,我没有得到任何错误

g++-4.7 -std=c++11 main.cpp

但是当我运行它时,出现了以下错误

In Main
terminate called after throwing an instance of 'std::system_error'
what():  Operation not permitted
Aborted (core dumped)

有人可以帮我解决我哪里出错了吗?

最佳答案

当我在 GCC 中使用 C++11 线程时,我使用:

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

这对我有用。

关于C++11 线程不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13227526/

相关文章:

C++ openCV - createFisherFaceRecognizer 未在此范围内声明

c# - 多线程: Value and Reference types

Python将变量从一个线程传递到另一个多线程

c - 编译标志 -I 之间的区别。并且没有-I。在海湾合作委员会

c++ - C++显示文件内容

java - 为什么 fopen 由于 Android-NDK 应用程序的权限问题而在 native 方法中失败?

c++ - 变量后的 Doxygen 多行注释

android - 在 onResume/onPause 中重新启动/暂停线程

c - gcc 编译错误 ‘sizeof’ 对不完整类型 ‘struct LadoSt’ 的无效应用

c++ - 如何使用 `openmp` 编译这个简单的 C++ 代码