[Boost-bugs] [Boost C++ Libraries] #6510: boost named_mutex example in documentation is wrong

Subject: [Boost-bugs] [Boost C++ Libraries] #6510: boost named_mutex example in documentation is wrong
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-02-01 19:04:52


#6510: boost named_mutex example in documentation is wrong
------------------------------------+---------------------------------------
 Reporter: nitinjavakid@… | Owner: matias
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: Documentation
  Version: Boost 1.46.1 | Severity: Problem
 Keywords: |
------------------------------------+---------------------------------------
 I have simplified the example mentioned in
 http://www.boost.org/doc/libs/1_48_0/doc/html/interprocess/synchronization_mechanisms.html

 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.


 #include <boost/interprocess/sync/scoped_lock.hpp>
 #include <boost/interprocess/sync/named_mutex.hpp>
 #include <fstream>
 #include <iostream>
 #include <cstdio>


 int main ()
 {
    using namespace boost::interprocess;

    try {
       named_mutex::remove("fstream_named_mutex");
       //Open or create the named mutex
       named_mutex mutex(open_or_create, "fstream_named_mutex");
       mutex.lock();
       std::ofstream file("file_name");

       for(int i = 0; i < 10; ++i){

          //Do some operations...

          //Write to file atomically
          file << "Process name, ";
          file << "This is iteration #" << i;
          file << std::endl;
       }
       mutex.unlock();
       named_mutex::remove("fstream_named_mutex");
    }
    catch(interprocess_exception &ex){
       std::cout << ex.what() << std::endl;
       return 1;
    }
    return 0;
 }

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/6510>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:08 UTC