Home Dashboard Directory Help
Search

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


Status: 

Closed
 as Duplicate Help for as Duplicate


1
0
Sign in
to vote
Type: Bug
ID: 786016
Opened: 5/1/2013 10:59:20 AM
Access Restriction: Public
0
Workaround(s)
view
1
User(s) can reproduce this bug

Description

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.

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

Thanks for reporting this bug. I've resolved it as a duplicate of http://connect.microsoft.com/VisualStudio/feedback/details/747145/ 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
stl@microsoft.com
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(http://support.microsoft.com)
Sign in to post a workaround.