Boost C++ Libraries: Ticket #6510: boost named_mutex example in documentation is wrong https://svn.boost.org/trac10/ticket/6510 <p> I have simplified the example mentioned in <a href="http://www.boost.org/doc/libs/1_48_0/doc/html/interprocess/synchronization_mechanisms.html">http://www.boost.org/doc/libs/1_48_0/doc/html/interprocess/synchronization_mechanisms.html</a> </p> <p> It seems that when we call remove, multiple processes enter the critical section together. I don't know whether its a bug in documentation or a regression on the boost library. This happens when I run 200 instances of the same program. </p> <p> #include &lt;boost/interprocess/sync/scoped_lock.hpp&gt; #include &lt;boost/interprocess/sync/named_mutex.hpp&gt; #include &lt;fstream&gt; #include &lt;iostream&gt; #include &lt;cstdio&gt; </p> <p> int main () { </p> <blockquote> <p> using namespace boost::interprocess; </p> </blockquote> <blockquote> <p> try { </p> <blockquote> <p> named_mutex::remove("fstream_named_mutex"); <em>Open or create the named mutex named_mutex mutex(open_or_create, "fstream_named_mutex"); mutex.lock(); std::ofstream file("file_name"); </em></p> </blockquote> </blockquote> <blockquote> <blockquote> <p> for(int i = 0; i &lt; 10; ++i){ </p> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> <em>Do some operations... </em></p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> <em>Write to file atomically file &lt;&lt; "Process name, "; file &lt;&lt; "This is iteration #" &lt;&lt; i; file &lt;&lt; std::endl; </em></p> </blockquote> <p> } mutex.unlock(); named_mutex::remove("fstream_named_mutex"); </p> </blockquote> <p> } catch(interprocess_exception &amp;ex){ </p> <blockquote> <p> std::cout &lt;&lt; ex.what() &lt;&lt; std::endl; return 1; </p> </blockquote> <p> } return 0; </p> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6510 Trac 1.4.3 anonymous Sat, 18 Aug 2012 15:13:03 GMT owner, component changed https://svn.boost.org/trac10/ticket/6510#comment:1 https://svn.boost.org/trac10/ticket/6510#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Matias Capeletto</span> to <span class="trac-author">Ion Gaztañaga</span> </li> <li><strong>component</strong> <span class="trac-field-old">Documentation</span> → <span class="trac-field-new">interprocess</span> </li> </ul> Ticket Ion Gaztañaga Thu, 30 Jun 2016 20:30:29 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/6510#comment:2 https://svn.boost.org/trac10/ticket/6510#comment:2 <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> I could not reproduce it with the latest version so closing it as fixed. </p> Ticket