Open
Description
std::cout 的生存期与进程的生存期绑定。这意味着,在屏幕上打印出“C++11”之前,std::cout 对象可能已经消失了。
英文原书都一个意思
std::cout’s lifetime is bound to the lifetime of the process. This means that the thread thr may be gone before std::cout prints C++11 onscreen.
在新版的 C++CoreGuidelines F.53 中,倒是没有了这段描述。
我想讨论目前描述的合理性,用户使用 detach 应该必然要求且保证 detach 的线程在主线程、进程执行完毕之前,就会结束。如果没有,那也不单单是 std::cout 会出现问题了。
比如b乎聊过的。