2013-10-23 42 views
-1
#include <iostream> 
#include <thread> 

int main() 
{ 
    std::thread th([] { std::cout << "Hello, World\n"; }); 
    th.join(); 
} 

這就是我所有的,它會導致運行時錯誤。這是爲什麼?我正在使用GCC 4.8(Ideone)。爲什麼我會爲這個簡單的線程例子得到一個運行時錯誤?

+1

您可以發佈命令行參數嗎?你把'-pthread'傳給g ++了嗎? – Praetorian

+0

@Praetorian Ideone不允許使用命令行參數。 –

+0

嘗試一些更好的然後像[Coliru](http://coliru.stacked-crooked.com/)(雖然它現在似乎有一些問題:)) – Praetorian

回答

1

從ideone的錯誤是:啓用多線程使用std ::線程:操作不允許

扔 '的std :: SYSTEM_ERROR'
什麼()的一個實例後終止叫

這意味着您需要使用@Praetorian已經建議的編號-pthread

該代碼在Visual Studio 2012中運行良好。

+0

在coliru中不起作用 - http://coliru.stacked-crooked.com/a/3d87e9ac944f31f1 –

+0

但是Coliru最近一直沒有工作,所以我會給你帶來懷疑的好處。謝謝! –

+0

@MemyselfandI:coliru.stacked-crooked.com現在有問題,沒有程序在其中工作。 – deepmax

相關問題