Boost C++ Libraries: Ticket #7552: win_iocp_io_service hangs due to a race condition https://svn.boost.org/trac10/ticket/7552 <p> The fix to <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6321" title="#6321: Bugs: non-paged pool memory leak in win_iocp_io_service (closed: fixed)">#6321</a> introduced a bug that can cause the io_service to hang. </p> <p> Example code (hangs eventually): </p> <pre class="wiki">int main() { for (;;) { boost::asio::io_service ios; ios.post([]{ std::cout &lt;&lt; '.'; }); boost::thread_group threads; for (size_t i = 0; i &lt; 2; ++i) threads.create_thread([&amp;]{ ios.run(); }); threads.join_all(); } } </pre><p> Suppose that one of the threads read the posted operation, completed it and got to the <em>work_finished</em> function where it decremented <em>outstanding_work</em> to 0 and entered the <em>stop</em> function. Now the second thread starts. In the <em>run</em> function it sees that <em>outstanding_work</em> is 0 so it sets <em>stopped</em> to 1 and returns. Back in the first thread <em><a class="missing wiki">PostQueuedCompletionStatus</a>(iocp_.handle, 0, 0, 0)</em> isn't called since <em>stopped</em> is already 1. <em>do_one</em> returns 1 and is called again. <em><a class="missing wiki">GetQueuedCompletionStatus</a></em> returns WAIT_TIMEOUT because the operation queue is empty, which causes the loop to continue to the next iteration ad infinitum. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7552 Trac 1.4.3 danielg@… Mon, 22 Oct 2012 14:52:59 GMT attachment set https://svn.boost.org/trac10/ticket/7552 https://svn.boost.org/trac10/ticket/7552 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">asiohang.patch</span> </li> </ul> <p> Proposed fix for this bug. </p> Ticket chris_kohlhoff Sun, 30 Dec 2012 23:17:22 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/7552#comment:1 https://svn.boost.org/trac10/ticket/7552#comment:1 <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> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/82290" title="Merge from trunk: * Fix some 64-to-32-bit conversion warnings. Fixes ...">[82290]</a>) Merge from trunk: </p> <ul><li>Fix some 64-to-32-bit conversion warnings. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7459" title="#7459: Bugs: warnings in boost::asio (closed: fixed)">#7459</a> </li></ul><ul><li>Fix typos in comments. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7761" title="#7761: Bugs: Minor comment typo in boost/asio/ssl/detail/stream_core.hpp (closed: fixed)">#7761</a> </li></ul><ul><li>Fix error in example embedded in basic_socket::get_option's documentation. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7562" title="#7562: Bugs: Old documentation for reading socket options (closed: fixed)">#7562</a> </li></ul><ul><li>Use long rather than int for SSL_CTX options, to match OpenSSL. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7209" title="#7209: Bugs: Asio SSL overflow in constant (closed: fixed)">#7209</a> </li></ul><ul><li>Use _snwprintf to address a compile error due to the changed swprintf signature in recent versions of MinGW. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7373" title="#7373: Bugs: Boost ASIO has a wrong swprintf interface definition for MinGW (closed: fixed)">#7373</a> </li></ul><ul><li>Fix deadlock that can occur on Windows when shutting down a pool of io_service threads due to running out of work. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7552" title="#7552: Bugs: win_iocp_io_service hangs due to a race condition (closed: fixed)">#7552</a> </li></ul><ul><li>Enable noexcept qualifier for error categories. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7797" title="#7797: Feature Requests: Add noexcept to conform with C++11 after #7278 (closed: fixed)">#7797</a> </li></ul><ul><li>Treat errors from accept as non-fatal. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7488" title="#7488: Bugs: Accept Errors (closed: fixed)">#7488</a> </li></ul><ul><li>Add a small block recycling optimisation. </li></ul><ul><li>Version bump. </li></ul><ul><li>Regenerate documentation. </li></ul> Ticket anonymous Wed, 24 Apr 2013 11:51:57 GMT <link>https://svn.boost.org/trac10/ticket/7552#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7552#comment:2</guid> <description> <p> Is this fixed in boost 1.53.0 ? </p> <p> I've noticed there are changes in win_iocp_io_service.ipp but not in the area pointed in the proposed patch, namely inside do_one() to prevent the infinite loop. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>chris_kohlhoff</dc:creator> <pubDate>Fri, 24 May 2013 03:10:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7552#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7552#comment:3</guid> <description> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/82263" title="Fix deadlock that can occur on Windows when shutting down a pool of ...">[82263]</a> </p> </description> <category>Ticket</category> </item> </channel> </rss>