std::thread get abort exception in destructor in vc++

前端 未结 1 1495
攒了一身酷
攒了一身酷 2021-01-21 04:36

I am getting abort exception in simple VC++ program when main method completes.

Here is my sample test program.

#include \"stdafx.h\"
#include 

        
相关标签:
1条回答
  • 2021-01-21 05:27

    This is documented in std::thread's destructor: if a thread is destroyed while it is joinable, std::terminate is called.

    Quote from the C++11 standard draft n3290 (§30.3.1.3 thread destructor):

    If joinable() then terminate(), otherwise no effects. [ Note: Either implicitly detaching or joining a joinable() thread in its destructor could result in difficult to debug correctness (for detach) or performance (for join) bugs encountered only when an exception is raised. Thus the programmer must ensure that the destructor is never executed while the thread is still joinable. — end note ]

    You must either join the thread, or detach it. Joining seems like the right option in your case.

    0 讨论(0)
提交回复
热议问题