问题描述
我正在尝试使用C ++ 0x线程,部分在gcc 4.5中实现,我遇到了一个我不明白的问题。让我们来看看这段代码。
#include< future>
#include< iostream>
int main()
{
std :: cout<< std :: async([](){return 10;})。get()<<的std :: ENDL;
}
这很简单,应该可以,但事实并非如此。它抛出std :: system_error
lockquote
抛出'std :: system_error'实例后终止调用
what():
aborted
what()返回空字符串,所以根本没有错误信息。更重要的是,它并不适用于使用gcc 4.5的在线编译器,但现在它可以工作。你可以在这里看到
$ b $但是昨天它抛出了同样的异常(尽管服务器没有做任何改变)。你知道什么是问题吗?
谢谢。
尝试与-lpthread链接。出于某种原因,线程库会在没有pthread的情况下编译,但会在运行时崩溃。
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;
}
it's quite simple and should work, but it's not. It throws std::system_error
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 herehttp://liveworkspace.org/code/f3003d62a758e047a880920c84f1241cbut yesterday it was throwing the same exception (though, no changes has been made on the server). Do you know what is the issue?
Thanks.
Try linking with -lpthread. For some reason the thread library does compile without pthreads but crashes at runtime.
这篇关于std ::未来的gcc实验性实现C ++ 0x的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!