Opened 11 years ago
Closed 6 years ago
#6510 closed Bugs (fixed)
boost named_mutex example in documentation is wrong
Reported by: | 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 , 10 years ago
Component: | Documentation → interprocess |
---|---|
Owner: | changed from | to
comment:2 by , 6 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I could not reproduce it with the latest version so closing it as fixed.