C ++ 11线程不工作 [英] C++11 Thread not working

查看:117
本文介绍了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;
}



当我使用下面的命令编译时没有错误

When I compile it using the following command I get no errors

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)

有人可以帮我处理错误吗? / p>

Could someone help me with where I am going wrong?

推荐答案

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

When I use C++11 threads with GCC, i use:

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


b $ b

这对我有用。

That works for me.

这篇关于C ++ 11线程不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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