Creating a global c++ object that used thread::join() in its destructor causes a lockup. - by Xiver1972

Status : 

  Duplicate<br /><br />
		This item appears to be a duplicate of another existing Connect or internal item.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 786016 Comments
Status Closed Workarounds
Type Bug Repros 1
Opened 5/1/2013 10:59:20 AM
Access Restriction Public


Creating a global c++ object, such as a singleton, that creates a thread and uses thread::join() in its destructor causes the compiled program to hang.

Sign in to post a comment.
Posted by Microsoft on 7/25/2013 at 2:46 PM

Thanks for reporting this bug. I've resolved it as a duplicate of which was submitted earlier. This is still on our list of bugs to fix, although it will not be fixed in VS 2013 RTM.

The problem is that the main thread is holding the atexit lock, destroying the global, and waiting for the worker thread to finish. The worker thread has almost finished, but it's calling _Cnd_do_broadcast_at_thread_exit(). That's calling _Call_once(), and that's initializing a mutex, then adding a cleanup function to the atexit list. That attempts to acquire the atexit lock, resulting in a classic deadlock. The hang can be avoided if the worker thread is signalled to finish, and given enough time to finish, before main starts exiting.

Stephan T. Lavavej
Senior Developer - Visual C++ Libraries
Posted by Microsoft on 5/2/2013 at 12:53 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 5/1/2013 at 11:54 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(