C++0x 的 gcc 实验实现上的 std::future 异常 [英] std::future exception on gcc experimental implementation of C++0x
问题描述
我正在试验 C++0x 线程,部分在 gcc 4.5 中实现,但我遇到了一个我无法理解的问题.让我们看看这段代码
I'm experimenting with C++0x threading, partially implemented in gcc 4.5 and I've got a problem, which I can't understand. Let's have a look on this code
#include <future>
#include <iostream>
int main()
{
std::cout << std::async([]() { return 10; }).get() << std::endl;
}
这很简单,应该可以工作,但事实并非如此.它抛出 std::system_error
it's quite simple and should work, but it's not. It throws std::system_error
在抛出 'std::system_error' 的实例后调用终止什么():中止
terminate called after throwing an instance of 'std::system_error' what(): Aborted
what() 返回空字符串,所以根本没有错误信息.更重要的是,它不能在使用 gcc 4.5 的在线编译器上工作,但现在它可以工作了.你可以在这里看到它http://liveworkspace.org/code/f3003d62a758e047a880920c84f1241c但昨天它抛出了同样的异常(虽然,服务器上没有进行任何更改).你知道是什么问题吗?
what() returns empty string, so there is no error information at all. More then that, it wasn't working on the online compiler, which uses gcc 4.5 as well, but now it works. You can see it here http://liveworkspace.org/code/f3003d62a758e047a880920c84f1241c but yesterday it was throwing the same exception (though, no changes has been made on the server). Do you know what is the issue?
谢谢.
推荐答案
尝试使用 -lpthread 链接.出于某种原因,线程库在没有 pthread 的情况下确实可以编译,但在运行时会崩溃.
Try linking with -lpthread. For some reason the thread library does compile without pthreads but crashes at runtime.
这篇关于C++0x 的 gcc 实验实现上的 std::future 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!