我只是在 GCC 4.7.2 中尝试一些新的 C++11 功能,尽管当我去运行时会发生 seg 错误。
$ ./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;
}