I need something like this:
void launch_task()
{
std::thread([](){ run_async_task(); });
}
Except thread's destructor will terminate my task. I don't need any control over the task, don't need a return value either. It just has to run its course and then the thread should terminate and C++ thread object should be disposed of. What C++ 11 facility do I need?
I've looked at std::async
, but couldn't find an example of usage for my case. It seems to be a pretty complicated system, and I'd need to somehow store and manipulate std::future
or it'd become synchronous (if my understanding is correct; I didn't find a good clear article on std::async
).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…