Just detach it immediately after creation.
std::thread([](){ run_async_task(); }).detach();
Once detached, the thread will no longer be joinable, so ~thread()
will have no effect.
This answer discusses more details of this behavior.
As mentioned by W.B. below, std::async
will not work for the following reason, pulled from this reference.
If the std::future obtained from std::async has temporary object
lifetime (not moved or bound to a variable), the destructor of the
std::future will block at the end of the full expression until the
asynchronous operation completes
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…