top | item 45655334

(no title)

leeter | 4 months ago

So there is a reason that in the C++ spec if a std::thread is still joinable when the destructor is called it calls std::terminate[1]. That reason being exactly this case. If the house is being torn down it's not safe to try to save the curtains[2]. Just let the house get torn down as quickly as possible. If you wanted to save the curtains (e.g. do things on the threads before they exit) you need to do it before the end of main and thus global destructors start getting called.

[1] https://en.cppreference.com/w/cpp/thread/thread/~thread.html

[2] https://devblogs.microsoft.com/oldnewthing/20120105-00/?p=86...

discuss

order

No comments yet.