从未来获取价值时的SIGABRT [英] SIGABRT when retrieving value from future
本文介绍了从未来获取价值时的SIGABRT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用C ++ 11期货时遇到问题.当我在 std :: async
返回的将来调用 wait()
或 get()
时,程序接收到 mutex
标头.可能是什么问题呢?如何解决?
I have a problem using C++11 futures. When I call wait()
or get()
on the future returned by std::async
, the program receives SIGABRT signal thrown from the mutex
header. What could be the problem? How to fix it?
我在Linux上使用g ++ 4.6.将以下代码粘贴到ideone.com会导致相同的问题.
I use g++ 4.6 on Linux. Pasting the following code to ideone.com causes the same problem.
#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 ++
来解决该问题.
The problem may be solved by adding -pthread
switch to g++
.
这篇关于从未来获取价值时的SIGABRT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文