Sto solo provando alcune delle nuove funzionalità di C++ 11 con GCC 4.7.2, anche se quando vado a eseguire un errore di seg si verifica.C++ 11 Errore sego asincrono
$ ./a.out
Message from main.
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
Aborted (core dumped)
ho compilato con le caratteristiche 'beta' di GCC, per quanto riguarda il C++ 0x con:
g++ -std=c++11 c11.cpp
Il codice:
#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;
}
+1. Grazie mille! – TheBlueCat
FWIW, l'aggiunta di -lpthread non ha funzionato, ma -pthread ha funzionato. –