std::future exception on gcc experimental implementation of C++0x

孤街醉人 提交于 2019-12-18 07:37:39

问题


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

terminate called after throwing an instance of 'std::system_error' what(): Aborted

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?

Thanks.


回答1:


Try linking with -lpthread. For some reason the thread library does compile without pthreads but crashes at runtime.



来源:https://stackoverflow.com/questions/3930700/stdfuture-exception-on-gcc-experimental-implementation-of-c0x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!