Opened 11 years ago

Closed 6 years ago

#6510 closed Bugs (fixed)

boost named_mutex example in documentation is wrong

Reported by: nitinjavakid@… Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: interprocess
Version: Boost 1.46.1 Severity: Problem
Keywords: Cc:

Description

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;

}

Change History (2)

comment:1 by anonymous, 10 years ago

Component: Documentationinterprocess
Owner: changed from Matias Capeletto to Ion Gaztañaga

comment:2 by Ion Gaztañaga, 6 years ago

Resolution: fixed
Status: newclosed

I could not reproduce it with the latest version so closing it as fixed.

Note: See TracTickets for help on using tickets.