Std::async
Example
auto runner = std::bind(&TickThread::runner, this, parameter);
std::future<bool> future = std::async(std::launch::async, runner);
if (future.valid()) {
future.wait();
}
Exception propagation
#include <future>
// ...
auto f = std::async(std::launch::async, []() -> int {
throw std::exception();
return 100;
});
try {
auto v = f.get();
} catch (...) {
std::cerr << "Exception!!";
}
wait()
는 예외 전파가 안되므로 get()
을 사용해야 한다.