Is a future safe to pass to a detached thread?
[basic.start.term]/6 If there is a use of a standard library object or function not permitted within signal handlers (21.10) that does not happen before (4.7) completion of destruction of objects with static storage duration and execution of
std::atexit
registered functions (21.5), the program has undefined behavior.
Per [basic.start.main]/5, returning from main
has the effect of calling std::exit
, which does destroy objects with static storage duration and execute std::atexit
registered functions. Therefore, I believe your example exhibits undefined behavior.