为什么我得到这个简单的线程示例的运行时错误? [英] Why do I get a runtime error for this simple thread example?
本文介绍了为什么我得到这个简单的线程示例的运行时错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <iostream>
#include <thread>
int main()
{
std::thread th([] { std::cout << "Hello, World\n"; });
th.join();
}
这是我所有,它会导致运行时错误。这是为什么?我使用GCC 4.8(Ideone)。
This is all I have and it causes a runtime error. Why is that? I'm using GCC 4.8 (Ideone).
推荐答案
ideone的错误是:
The error from ideone is:
在抛出std :: system_error的实例后调用终止
what():启用多线程以使用std :: thread:不允许操作
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
这意味着您需要使用 -pthread
Praetorian。
Which means you need to be compiling with -pthread
as already suggested by @Praetorian.
代码在Visual Studio 2012中运行良好。
The code runs fine in Visual Studio 2012.
这篇关于为什么我得到这个简单的线程示例的运行时错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文