Boost C++ Libraries: Ticket #7571: Mutex fails to unlock and causes deadlock https://svn.boost.org/trac10/ticket/7571 <p> I'm using mutex and scoped_lock to lock and unlock it. Once a thread locks the mutex, it never gets unlocked, even though the lock goes out of scope and even when the thread terminates. As a result it causes a deadlock. </p> <p> The problem shows only when the operation the thread is doing is long enough to allow context switching between the threads. </p> <p> Problem appears on Visual Studio 2003 (VC7.1) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7571 Trac 1.4.3 yalon-l@… Thu, 25 Oct 2012 14:06:00 GMT attachment set https://svn.boost.org/trac10/ticket/7571 https://svn.boost.org/trac10/ticket/7571 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">Main.cpp</span> </li> </ul> <p> Bug demonstrator </p> Ticket yalon-l@… Thu, 25 Oct 2012 14:16:21 GMT <link>https://svn.boost.org/trac10/ticket/7571#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7571#comment:1</guid> <description> <p> Results when running the attached demo file:<br /> </p> <p> D:\Projects\<a class="missing wiki">BoostMutexBug</a>\<a class="missing wiki">BoostMutexBug</a>\Tests\Debug&gt;Tests 5000000<br /> Thread 1, iteration 0<br /> Thread 2, iteration 0<br /> Thread 1, iteration 1<br /> Thread 1, iteration 2<br /> Thread 1, iteration 3<br /> Thread 1, iteration 4<br /> Deadlock occurred<br /> <br /> D:\Projects\<a class="missing wiki">BoostMutexBug</a>\<a class="missing wiki">BoostMutexBug</a>\Tests\Debug&gt;Tests 100<br /> Thread 1, iteration 0<br /> Thread 1, iteration 1<br /> Thread 2, iteration 0<br /> Thread 1, iteration 2<br /> Thread 2, iteration 1<br /> Thread 2, iteration 2<br /> Thread 2, iteration 3<br /> Thread 1, iteration 3<br /> Thread 1, iteration 4<br /> Thread 2, iteration 4<br /> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 28 Oct 2012 17:24:59 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7571#comment:2 https://svn.boost.org/trac10/ticket/7571#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> The problem is in your example. The timeout should depend on MAX_COUNTS. When MAX_COUNTS 5000000, it seems that 10000 milliseconds is not enough to do the loop :( </p> Ticket yalon-l@… Mon, 29 Oct 2012 08:34:07 GMT attachment set https://svn.boost.org/trac10/ticket/7571 https://svn.boost.org/trac10/ticket/7571 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">Tests.exe</span> </li> </ul> <p> Executable of the bug demo </p> Ticket anonymous Mon, 29 Oct 2012 08:44:48 GMT <link>https://svn.boost.org/trac10/ticket/7571#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7571#comment:3</guid> <description> <p> I don't think that the problem is in the example. The 10000 milliseconds is about 10 times the needed duration. I'm attacing the executable so one can see the messages written and then a long pause (of about 9 sec) after which deadlock is detected. I can increase of course the 10000, but it does nothing except for a longer wait till the program detects the deadlock. </p> <p> I forgot to mention that I'm running on Windows 7. </p> <p> In my experiments, I replace boost::mutex with a mutex of my own, based upon Windows native <a class="missing wiki">CreateMutex</a>. With it the problem doesn't show and the deadlock never occurs. </p> </description> <category>Ticket</category> </item> <item> <author>yalon-l@…</author> <pubDate>Mon, 29 Oct 2012 08:49:43 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/7571#comment:4 https://svn.boost.org/trac10/ticket/7571#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">invalid</span> </li> </ul> Ticket viboes Mon, 29 Oct 2012 16:49:57 GMT <link>https://svn.boost.org/trac10/ticket/7571#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7571#comment:5</guid> <description> <p> I don't reach to reproduce the deadlock on <a class="missing wiki">MacOs/Ubuntu/Windows</a> XP. </p> <p> Could you replace the timed join by join and report what happens? Please, could you try to debug this issue on your side? </p> </description> <category>Ticket</category> </item> <item> <author>Yalon Lotan <yalon-l@…></author> <pubDate>Wed, 31 Oct 2012 13:38:49 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7571#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7571#comment:6</guid> <description> <p> Replacing the timed join by join didn't change a thing, except that the program now hangs forever instead of announcing that it had detected a deadlock... I'm surprised that you didn't manage to reproduce the bug on Windows XP. Did you try building it or using the attached exe? Running the exe on XP reproduced the bug for me. The same applies to building and running it on XP. </p> <p> If you build it, pay attention to use Visual Studio 2003. I gave the code to a colleague with Visual Studio 2005 and with that compiler that problem didn't show. </p> <p> I can debug the problem on my side. What information would be useful for you? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 31 Oct 2012 21:11:12 GMT</pubDate> <title>status, severity changed; resolution set https://svn.boost.org/trac10/ticket/7571#comment:7 https://svn.boost.org/trac10/ticket/7571#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> <li><strong>severity</strong> <span class="trac-field-old">Showstopper</span> → <span class="trac-field-new">Problem</span> </li> </ul> <p> I have added the test to the regression test. For the time been no compiler is signaling a failure. </p> <p> VS 2003 is too old to maintain it now, in 2012. </p> <p> For the debug, I'm not waiting for any specific information other than, Hey, I have found what is happening? or better yet, And I've found a workaround ;-) </p> <p> No seriously, I don't have the possibility and the time to debug this issue, but any patch is welcome. </p> Ticket