Boost C++ Libraries: Ticket #11069: io_service hangs for 5 minutes https://svn.boost.org/trac10/ticket/11069 <p> Everything said below is applicable to Linux, 64-bit, CentOS 6.6, compiled by g++ 4.4. </p> <p> I have an io_service object which is runned by several threads. According to the logic at the program finish all sockets which belong to this io_service are closed and these threads begin to exit one by one. </p> <p> Just before threads exits, it posts on the io_service a callback which joins this thread from another thread and cleans up some associated data. </p> <p> Everything runs perfect until only one thread is left. Occasionally this thread is not running any posted event for exactly 5 minutes. It is just waiting for something. After 5 minutes it wakes up, joins all the the threads which were posted, and successfully exits. It doesn't happen all the time, but approx. every 50 program executions I get this situations. </p> <p> According to asio sources, epoll reactor has some timeout which equals to exactly 5 minutes. It seems that there is a bug somewhere. </p> <p> P.S.: Meanwhile the main program thread waits for condition_variable which is set by the last thread running io_service, which signals that all the threads exited. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11069 Trac 1.4.3 dmitrmax@… Fri, 06 Mar 2015 14:23:55 GMT attachment set https://svn.boost.org/trac10/ticket/11069 https://svn.boost.org/trac10/ticket/11069 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost.patch</span> </li> </ul> Ticket dmitrmax@… Fri, 06 Mar 2015 14:43:31 GMT <link>https://svn.boost.org/trac10/ticket/11069#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11069#comment:1</guid> <description> <p> The bug was fixed. It is a race condition. It happens in following conditions: 1) io_service::run_one() is used to execute works; 2) only two threads calling run_one() left; 3) one of these threads is executing handler completion; 4) handler posts another operation into the op_queue and after it the first thread doesn't call run_one() anymore. 5) meanwhile after the first thread started handler completion but before handler posted the new op, the second thread is running reactor (epoll_reactor in my case). </p> <p> After the first thread has executed the handler completion, it should check for new works, and if there are some new works, wake up a thread or interrupt reactor running. I put this logic into work_cleanup object. </p> </description> <category>Ticket</category> </item> <item> <author>dmitrmax@…</author> <pubDate>Fri, 06 Mar 2015 15:02:54 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/11069 https://svn.boost.org/trac10/ticket/11069 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost.2.patch</span> </li> </ul> <p> V2 version of patch. First is not correct. </p> Ticket