GCC 4.7.2 でいくつかの新しい C++11 機能を試しているところですが、実行しようとすると seg fault が発生します。
$ ./a.out
Message from main.
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
Aborted (core dumped)
c++0xに関して、GCCの「ベータ」機能でコンパイルしました:
g++ -std=c++11 c11.cpp
コード:
#include <future>
#include <iostream>
void called_from_async() {
std::cout << "Async call" << std::endl;
}
int main() {
//called_from_async launched in a separate thread if possible
std::future<void> result( std::async(called_from_async));
std::cout << "Message from main." << std::endl;
//ensure that called_from_async is launched synchronously
//if it wasn't already launched
result.get();
return 0;
}