我在使用 C++11 future 时遇到问题。当我对 std::async
返回的 future 调用 wait()
或 get()
时,程序接收到从 抛出的 SIGABRT 信号code>mutex
header 。可能是什么问题呢?如何解决?
我在 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;
}
最佳答案
将-pthread
开关添加到g++
可能会解决问题。
关于c++ - 从 future 检索值(value)时的 SIGABRT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7967790/