【发布时间】:2011-11-01 14:14:26
【问题描述】:
我在使用 C++11 期货时遇到问题。当我在std::async 返回的未来调用wait() 或get() 时,程序接收到从mutex 标头抛出的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;
}
【问题讨论】:
-
@Anders K.:这在这里似乎没有任何用处。如果默认启动策略没有崩溃,我会对它感到满意。