Boost C++ Libraries: Ticket #8354: Only thread blocked in io_service.run() is not processing event loop. https://svn.boost.org/trac10/ticket/8354 <p> There is a concurrency issue in <code>task_io_service</code> (Boost 1.48+), that can leave a thread blocked in <code>io_service.run()</code>, waiting for its <code>wakeup_event</code> to be signaled. If thread A invokes <code>io_service::poll()</code>, runs the reactor while thread B invokes <code>io_service.run()</code>, becoming an idle thread (<code>op_queue_</code> is empty), then if no work is ready to run, thread A <code>io_service::poll()</code> returns <code>0</code> without waking up the idle thread B. This results in thread B remaining blocked on <code>io_service::run()</code>, but never processing the event loop. </p> <p> A side-by-side visualization illustrating the problem: </p> <pre class="wiki"> poll thread | main thread ---------------------------------------+--------------------------------------- lock() | do_poll_one() | |-- pop task_operation_ from | | queue_op_ | |-- unlock() | lock() |-- create task_cleanup | do_run_one() |-- service reactor (non-block) | `-- queue_op_ is empty |-- ~task_cleanup() | |-- set thread as idle | |-- lock() | `-- unlock() | `-- queue_op_.push( | | task_operation_) | `-- task_operation_ is | queue_op_.front() | `-- return 0 | // still waiting on wakeup_event unlock() | </pre><p> Attached files are: </p> <ul><li>Patch file that modifies <code>task_io_service.ipp</code> to sleep immediately after <code>do_poll_one</code> runs the reactor. This is only used to increase the changes of reproducing the concurrency problem. </li><li>Test application: <ul><li>An asynchronous work loop via a timer that will print "." every 3 seconds. </li><li>Spawn off a single thread that will poll the <code>io_service</code>. </li><li>Delay to allow the new thread time to poll <code>io_service</code>, and have main call <code>io_service::run()}} while the poll thread sleeps in {{{task_io_service::do_poll_one()</code>. </li></ul></li><li>Patch with suggested fix that invokes <code>wake_one_thread_and_unlock()</code> before <code>do_poll_one</code> returning <code>0</code> if no work is to be done after running the reactor. </li></ul> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8354 Trac 1.4.3 Tanner Sansbury <twsansbury@…> Sat, 30 Mar 2013 17:54:10 GMT attachment set https://svn.boost.org/trac10/ticket/8354 https://svn.boost.org/trac10/ticket/8354 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test.patch</span> </li> </ul> <p> Patch task_io_service to increase changes of reproducing concurrency problem. </p> Ticket Tanner Sansbury <twsansbury@…> Sat, 30 Mar 2013 17:55:16 GMT attachment set https://svn.boost.org/trac10/ticket/8354 https://svn.boost.org/trac10/ticket/8354 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test.cpp</span> </li> </ul> <p> Test application used with test.patch task_io_service. </p> Ticket Tanner Sansbury <twsansbury@…> Sat, 30 Mar 2013 17:55:39 GMT attachment set https://svn.boost.org/trac10/ticket/8354 https://svn.boost.org/trac10/ticket/8354 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">fix.patch</span> </li> </ul> <p> Proposed fix. </p> Ticket samjmill@… Wed, 03 Apr 2013 22:14:21 GMT cc set https://svn.boost.org/trac10/ticket/8354#comment:1 https://svn.boost.org/trac10/ticket/8354#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">samjmill@…</span> added </li> </ul> Ticket David Schwartz <davidjoelschwartz@…> Sat, 06 Apr 2013 01:37:09 GMT cc changed https://svn.boost.org/trac10/ticket/8354#comment:2 https://svn.boost.org/trac10/ticket/8354#comment:2 <ul> <li><strong>cc</strong> <span class="trac-author">davidjoelschwartz@…</span> added </li> </ul> Ticket chris_kohlhoff Fri, 24 May 2013 03:34:48 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/8354#comment:3 https://svn.boost.org/trac10/ticket/8354#comment:3 <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">fixed</span> </li> </ul> <p> Fixed on trunk in <a class="changeset" href="https://svn.boost.org/trac10/changeset/84348" title="Fix a problem with lost thread wakeups that can occur when making ...">[84348]</a>. Merged to release in <a class="changeset" href="https://svn.boost.org/trac10/changeset/84388" title="Merge from trunk. ...">[84388]</a> </p> Ticket