Boost C++ Libraries: Ticket #2570: boost::interprocess::message_queue::timed_send and timed_receive bug https://svn.boost.org/trac10/ticket/2570 <p> In boost::interprocess::message_queue, the timed_send and timed_receive methods may return true without actually performing the send or receive operation. </p> <p> The problem lies in boost/interprocess/ipc/message_queue.hpp, in the logic that handles blocking behavior for these two methods. Both implementations have the same form: </p> <p> if (&lt;operation-would-block&gt;) { </p> <blockquote> <p> switch(block){ </p> <blockquote> <p> ... case timed : do{ </p> <blockquote> <p> if(!&lt;condition-variable&gt;.timed_wait(lock, abs_time)) </p> <blockquote> <p> return !&lt;operation-would-block&gt;; </p> </blockquote> </blockquote> <p> } while (&lt;operation-would-block&gt;); break; ... </p> </blockquote> <p> } </p> </blockquote> <p> } </p> <p> The problem is that when timed_wait returns false, it might be possible to complete the operation without blocking (i.e. there might be something in the queue in the case of receive, or the queue might not be full in the case of send). Therefore, in rare cases, timed_send/timed_receive return true, without having actually done any work. </p> <p> My proposed fix is to change the timed case to: </p> <blockquote> <p> do{ </p> <blockquote> <p> if(!&lt;condition-variable&gt;.timed_wait(lock, abs_time)) { </p> <blockquote> <p> if(&lt;operation-would-block&gt;) { </p> <blockquote> <p> return false; </p> </blockquote> <p> } break; </p> </blockquote> <p> } </p> </blockquote> <p> } while (&lt;operation-would-block&gt;); </p> </blockquote> <p> After I apply this change to my own boost install, the problem disappears. </p> <p> I observed this bug on Linux (some Debian 4 flavor, 32-bit) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2570 Trac 1.4.3 Ion Gaztañaga Fri, 05 Dec 2008 22:58:25 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2570#comment:1 https://svn.boost.org/trac10/ticket/2570#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> Fixed in revision 50146 </p> Ticket Tony Astolfi <aastolfi@…> Mon, 08 Dec 2008 15:11:59 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/2570#comment:2 https://svn.boost.org/trac10/ticket/2570#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2570#comment:1" title="Comment 1">igaztanaga</a>: </p> <blockquote class="citation"> <p> Fixed in revision 50146 </p> </blockquote> <p> Fix for timed_send looks good. </p> <p> Fix for timed_receive is missing curly-braces around the outer if body. </p> Ticket Ion Gaztañaga Mon, 08 Dec 2008 16:27:33 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2570#comment:3 https://svn.boost.org/trac10/ticket/2570#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Sorry! Fixed in revision 50194. </p> Ticket