c++ - 从 future 检索值(value)时的 SIGABRT

标签 c++ c++11

我在使用 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/

相关文章:

c++ - const * const * 成员变量初始化c++

c++ - 通过引用辅助函数传递随机数生成器 mt19937 是否正确?

c++ - GLFW keycallback 用户指针不携带数据

c++ - set_new_handler 是否将 new_handler 存储在线程本地存储中?

c++ - 为什么我收到错误 : invalid operands to binary expression after overloaded += operand?

c++ - cin 空间问题

c++ - 如果我的钱有限,如何在 DAG 中找到最便宜的方式?

c++ - 未解析的外部符号 _D3D10CreateDeviceAndSwapChain@32 在函数“public : bool 中引用

c++ - 从 CUDA 数组中删除元素

c++11 - 使用 gdb 调试 C++11 右值引用