Folks,<div>    There is a race condition in the basic pthread mutex lock code for dbus.</div><div><br></div><div>Thread 1:</div><div>   Calls _dbus_connection_acquire_io_path -&gt; grabs the mutex -&gt;  io_path_acquired = true -&gt; releases the mutex -&gt; exits the function.</div>

<div><br></div><div>Thread 2: </div><div>   Calls _dbus_connection_acquire_io_path -&gt; grabs the mutex -&gt; io_path_acquired is already true -&gt; _dbus_condvar_wait_timeout</div><div><br></div><div>Thread 1:</div><div>

   Calls _dbus_connection_release_io_path -&gt; grabs the mutex -&gt; sets io_path_acquired = false -&gt; signals thread 1 and releases the mutex.</div><div>    </div><div>    Calls _dbus_connection_acquire_io_path again tries to grab the mutex.</div>

<div>   </div><div><br></div><div>Now, in _dbus_pthread_condvar_wait_timeout:</div><div><br></div><div>     result = pthread_cond_timedwait (&amp;pcond-&gt;cond, &amp;pmutex-&gt;lock, &amp;end_time);</div><div>    ......</div>

<div>  _dbus_assert (pmutex-&gt;count == 0);</div><div>  pmutex-&gt;count = old_count;</div><div>  pmutex-&gt;holder = pthread_self(); </div><div><br></div><div><br></div><div>We set the holder back to Thread 2 only after some time.</div>

<div>During this time Thread 1 can grab the mutex since pthread-&gt;holder is still set to Thread1.  In _dbus_pthread_mutex_lock function</div><div>that check is enough to grab the lock.</div><div><br></div><div>So currently, Thread 2 has woken up from cond_timewait -&gt; gone back to the acquire_io_path_function and set io_path_acquired to true.</div>

<div><br></div><div>Thread 1, has been able to grab the mutex -&gt; checks io_path_acquired variable, sees that it already true -&gt; calls condvar_wait_timeout.</div><div><br></div><div>which asserts that the pthread-&gt;holder and pthread_self is the same. This assert will fail.</div>

<div><br></div><div>Hope the above make sense. The attached patch fixes the problem for me.</div><div><br>Thanks</div>