When trying to answer another Stackoverflow question, I realized that this simple C++11 snippet is implicitly blocking the calling thread:
std::async(std::launch::async, run_async_task)
To me this would have seemed the canonical C++11 way to launch a task asynchronously without caring about the result. Instead one has to apparently explicitly create and detach a thread (see answer to mentioned question) in order to achieve this.
So here's my question: Is there any reason in regards to safety/correctness that the destructor of a std::future
has to be blocking? Wouldn't it be enough if it blocks on get
only and otherwise, if I'm not interested in the return value or exception, it's simply fire and forget?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…