Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...