Boost C++ Libraries: Ticket #80: Bosot.Thread.condition(win32).notify_all https://svn.boost.org/trac10/ticket/80 <pre class="wiki">Problem:this is a bug in the notify_all() methode in "Boost.Thread.Condition(win32)". Why:the bug causes a deadlock in my machine. Desc: -&gt;suppose that i have two thread waiting for a condition, then the condition state will be ( m_block = 2, m_waiting = 0, m_gon = 0, the queue semaphore's count become = -2, and the mutex state unlocked). -&gt;then suppose that there is another thread call the notify_one() methode of the shared condition ,thus the state of the condition become (m_block = 1, m_waiting = 1, m_gon = 0, the queue semaphore's count = -1, and the mutex state unlocked) -&gt; then this thread or another reschudled before the waked up thread from the queue and called the notify_all() methode, it will find that m_waiting != 0 , and m_block != 0 and the state of the condition become after this call (m_block = 0, m_waiting = 2, m_gon = 0, the queue semaphore's count = -1(bug), and the muext state locked(deadlock)). **-&gt; thus when we noted that there are a bug in the queue semaphore's count, and a deadlock in the mutex state that was unlocked. Bug Fix: here is the new version of the methode after correcting the bug. void condition::notify_all() { unsigned signals = 0; int res; res = WaitForSingleObject(reinterpret_cast&lt;HANDLE&gt; (m_mutex), INFINITE); assert(res == WAIT_OBJECT_0); if (m_waiting != 0) // the m_gate is already closed { if (m_blocked == 0) { res = ReleaseMutex(reinterpret_cast&lt;HANDLE&gt; (m_mutex)); assert(res); return; } m_waiting += (signals = m_blocked); m_blocked = 0; } else { res = WaitForSingleObject (reinterpret_cast&lt;HANDLE&gt;(m_gate), INFINITE); assert(res == WAIT_OBJECT_0); if (m_blocked &gt; m_gone) { if (m_gone != 0) { m_blocked -= m_gone; m_gone = 0; } signals = m_waiting = m_blocked; m_blocked = 0; } else { res = ReleaseSemaphore (reinterpret_cast&lt;HANDLE&gt;(m_gate), 1,0); assert(res); } } res = ReleaseMutex(reinterpret_cast&lt;HANDLE&gt; (m_mutex)); assert(res); if (signals) { res = ReleaseSemaphore(reinterpret_cast&lt;HANDLE&gt; (m_queue), signals, 0); assert(res); } Note : sorry for my bed english. name: walead mohammed. thanks. </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/80 Trac 1.4.3 Markus Schöpflin Thu, 24 Nov 2005 09:49:36 GMT status changed https://svn.boost.org/trac10/ticket/80#comment:1 https://svn.boost.org/trac10/ticket/80#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> </ul> <pre class="wiki">Logged In: YES user_id=91733 From source code review I concluded that the current CVS version contains exactly the code given above. Therefore I consider this as fixed. </pre> Ticket