2011-11-01 63 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++来解决。