【问题标题】:SIGABRT when retrieving value from future从未来检索价值时的 SIGABRT
【发布时间】: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;
}

【问题讨论】:

标签: c++ c++11


【解决方案1】:

问题可以通过在g++中添加-pthread开关解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-29
    • 1970-01-01
    • 1970-01-01
    • 2018-02-17
    • 1970-01-01
    相关资源
    最近更新 更多