Boost C++ Libraries: Ticket #5840: thread.cpp: race condition in thread_proxy's thread state
https://svn.boost.org/trac10/ticket/5840
<p>
Using BOOST_HAS_PTHREADS to clarify the code, but all paths appear to suffer.
</p>
<pre class="wiki">extern "C" {
static void* thread_proxy(void* param)
{
// try
{
thread_param* p = static_cast<thread_param*>(param);
boost::function0<void> threadfunc = p->m_threadfunc;
p->started();
threadfunc();
}
...
}
</pre><p>
p->started() is called *before* the actual thread function. started() will change state even if an exception occurs such that the thread is not actually started:
</p>
<pre class="wiki">void started()
{
boost::mutex::scoped_lock scoped_lock(m_mutex);
m_started = true;
m_condition.notify_one();
}
</pre>en-usBoost C++ Libraries/htdocs/site/boost.png
https://svn.boost.org/trac10/ticket/5840
Trac 1.4.3Jeffrey Walton <noloader@…>Wed, 31 Aug 2011 00:45:02 GMTcomponent changed; owner set
https://svn.boost.org/trac10/ticket/5840#comment:1
https://svn.boost.org/trac10/ticket/5840#comment:1
<ul>
<li><strong>owner</strong>
set to <span class="trac-author">Anthony Williams</span>
</li>
<li><strong>component</strong>
<span class="trac-field-old">None</span> → <span class="trac-field-new">thread</span>
</li>
</ul>
TicketviboesFri, 02 Dec 2011 23:00:36 GMTowner, status changed; cc set
https://svn.boost.org/trac10/ticket/5840#comment:2
https://svn.boost.org/trac10/ticket/5840#comment:2
<ul>
<li><strong>cc</strong>
<span class="trac-author">viboes</span> added
</li>
<li><strong>owner</strong>
changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span>
</li>
<li><strong>status</strong>
<span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span>
</li>
</ul>
<p>
notify_one doesn't throws. So the single function that could be throw after setting m_started is the unlock implied by the scoped_lock. You should admit that there are not too many situations on which can lock a mutex and immediately after we can not unlock it, isn't it. This will be catastrophic, our system will stay with a mutex locked :(
</p>
<p>
So in reality I don't think we can fall in the situation you described, or maybe I am missing something important.
</p>
TicketviboesWed, 07 Dec 2011 00:38:21 GMTtype changed
https://svn.boost.org/trac10/ticket/5840#comment:3
https://svn.boost.org/trac10/ticket/5840#comment:3
<ul>
<li><strong>type</strong>
<span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Support Requests</span>
</li>
</ul>
<p>
Move so Support request until resolution clarified.
</p>
TicketviboesTue, 20 Dec 2011 17:24:57 GMTstatus, type changed; resolution set
https://svn.boost.org/trac10/ticket/5840#comment:4
https://svn.boost.org/trac10/ticket/5840#comment:4
<ul>
<li><strong>status</strong>
<span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span>
</li>
<li><strong>type</strong>
<span class="trac-field-old">Support Requests</span> → <span class="trac-field-new">Bugs</span>
</li>
<li><strong>resolution</strong>
→ <span class="trac-field-new">invalid</span>
</li>
</ul>
<p>
It seems the described situation can not be occur.
</p>
<p>
Please, reopen it if you don't agree with the resolution.
</p>
Ticket