我在使用 C++11 future 时遇到问题。当我打电话时wait()
or get()
关于返回的未来std::async
,程序接收从mutex
标头。可能是什么问题呢?如何修复它?
我在 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++
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)