2011-11-01 57 views
3

我有一個使用C++ 11期貨的問題。當我在std::async返回的未來上撥打wait()get()時,程序將收到從mutex標題中拋出的SIGABRT信號。可能是什麼問題呢?如何解決它?SIGABRT從未來檢索價值

我在Linux上使用g ++ 4.6。將以下代碼粘貼到ideone.com會導致同樣的問題。

#include <future> 
#include <thread> 

int calculate() { 
    return 1; 
} 

int main() { 
    auto result = std::async(calculate); 
    result.wait();// <-- this aborts 
    int value = result.get();// <-- or this aborts as well if previous line is commented out. 

    return 0; 
} 
+1

也許看看這個:http://stackoverflow.com/questions/4426141/asynchronous-function-call-c0x –

+0

@Anders K .:這似乎沒有任何用處。如果它沒有崩潰,我會對默認啓動策略感到滿意。 –

回答

2

的問題可以通過將-pthread開關g++來解決。