Boost logo

Boost Users :

Subject: [Boost-users] [interprocess] named mutex clean up
From: Chard (boost_at_[hidden])
Date: 2009-04-07 16:55:12


Does calling named_mutex::remove() have consistent cross-platform behaviour?

The reason I ask is that I am trying to use a named mutex for an "I'm the
only process" check.

That is, the process takes a shared lock on the named mutex (at start up),
then, at points within the program, it attempts to get an exclusive lock in
order to perform the check/actions. When finished, the mutex is returned to
a shared lock.

The problem is, if a process dies in some unforeseen manner - and does not
get to call named_mutex::remove() - the named_mutex is left orphaned in the
system (in a shared lock) such that other processes can never get an
exclusive lock.

On the Windows platform, I've found I can call named_mutex::remove() at
start up, which seems to clean up the named_mutex if it is orphaned, or just
do nothing if another, active, process has a lock - exactly the behaviour I
require.

However, is this platform independent, and a suitable technique?


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net