Po prostu próbuję kilka nowych funkcji C++ 11 z GCC 4.7.2, ale kiedy idę do uruchomienia, pojawia się błąd seg.C++ 11 Async seg fault
$ ./a.out
Message from main.
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
Aborted (core dumped)
skompilowany z funkcji 'beta' GCC, w odniesieniu do C++ 0x z:
g++ -std=c++11 c11.cpp
Kod:
#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. Dziękuję bardzo! – TheBlueCat
FWIW, dodanie samego -lpthread nie działało, ale -pthread zrobił to. –