Andrew Agno wrote:
I'm trying to run the following program, which works under Linux, on an intel mac:
#include
#include #include #include <iostream> using namespace std; namespace bi = boost::interprocess;
int main( int argc, char **argv ) { cout << "Creating mutex" << endl; try { bi::named_mutex directoryMutex( bi::create_only, "MyVeryUniquelyNamedMutex" ); cout << "Creating scoped lock" << endl; bi::scoped_lockbi::named_mutex lock( directoryMutex ); cout << "All reqs met. Destroying mutex" << endl; bi::named_mutex::remove( "MyVeryUniquelyNamedMutex" ); } catch( std::exception &e ) { cout << "Problem encountered: " << e.what() << endl; }
return 0; }
I don't have a MacOs to test the code and I didn't know people was trying to use it with MacOS. But glad to know you are trying. Anyway, you are erasing the mutex and the before the scoped_lock destructor is called. That means that the destructor of the scoped_lock will try to access to a mutex that's already destroyed. This does not seem correct. The "remove" function should be after the mutex is used. Something like: try { { bi::named_mutex directoryMutex( bi::create_only, "MyVeryUniquelyNamedMutex" ); cout << "Creating scoped lock" << endl; bi::scoped_lockbi::named_mutex lock( directoryMutex ); cout << "All reqs met. Destroying mutex" << endl; } bi::named_mutex::remove( "MyVeryUniquelyNamedMutex" ); } catch( std::exception &e ) { cout << "Problem encountered: " << e.what() << endl; } Unless, of course, that you need to destroy the mutex while it's been used (something for which, I have no solution). Regards, Ion