Boost logo

Boost Users :

Subject: [Boost-users] [interprocess] Named mutex
From: Chard (boost_at_[hidden])
Date: 2010-12-01 16:01:48


Ion, anyone,

I'm trying to use a named mutex to control access to a file. The example
given here:

http://www.boost.org/doc/libs/1_45_0/doc/html/interprocess/synchronization_mechanisms.html#interprocess.synchronization_mechanisms.mutexes.mutexes_named_example

seems to be a starting point. However, I'm not exactly sure what this
example is demonstrating. For example:

- it appears to be attempting to control access to a file called
"file_name". However, streams are opened on the file so, AFAICT, if
interleaving calls from two processes stream out to it, the outcome will be
unpredictable (even under controlled lock, due to the file-pointer position)
?

- the file is thrown away at process exit; what would this mean if the other
process is accessing it?

- the 'mutex_remove' object causes removal of the named mutex on
construction. I presume this is to demonstrate a clean up of a residual
named mutex if a previous execution did not exit cleanly. However, if
process 1 starts up and executes until just after the mutex creation, then
process 2 starts up and executes the mutex_remove, the mutex appears to be
in an invalid state, and the scoped_lock calls have no effect - this is
certainly the case on Windows. This would defeat the whole point.

Any clarification appreciated...


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