1

I have a resource which I need to protect access to within a process, and across multiple processes. I've managed this by creating a named mutex via boost::interprocess:named_recursive_mutex, and it works great.

#include <boost/interprocess/sync/named_recursive_mutex.hpp>
boost::interprocess::named_recursive_mutex mut(
    boost::interprocess::open_or_create, "MY_SHARED_MUTEX_123");

However, it's to my understanding that this should be cleaned up eventually via remove(), ie:

mut.remove("MY_SHARED_MUTEX");

However, this call appears to completely clobber the mutex, rather than check/decrement a reference count, so I'm trying to find a safe way to issue the remove() call when I know that no other processes are using it. I could create a chunk of shared memory via boost as well, but that does not appear to have a shared reference count either.

I've found a similar question on SO, but the accepted answer doesn't seem adequate for my needs, as it just refers to the "boost docs", but doesn't give a clear indicator as to when remove() can be safely issued.

How can I safely clean up this named mutex when I'm certain the last process accessing it has closed, or possibly crashed?

Thank you.

4

1 に答える 1