Boost logo

Boost Users :

From: Sachin Garg (schngrg_at_[hidden])
Date: 2008-07-29 05:23:01


When using semaphores to synchronize separate processes, everything
works fine when each process exits nicely (closing its semaphores
before exit). But things get really messy when a process might crash.
I am unable to figure out how to recover from such a crash which
leaves semaphores in inconsistent state.

If a semaphore is not in-use (open) by any process, in this case (in
my application) I can safely 'remove' it and start afresh. Is there
some way to find out if any process is using a semaphore at a time so
that I can call 'remove'?

When I just add a 'remove' on process start this works great on
windows (as remove just fails if another process has the semaphore
open), but on linux sem_unlink is used which has the behavior of
deleting it even if its in use.

What is the general practice when it comes to cleaning up semaphores
after process crashes? Maybe some way to ensure that 'post' and
'close' are always called even when application has otherwise crashed?
Is there some way to use boost's windows style semaphores on linux
instead of native posix style?

I tried looking and many have asked this question (in context of
recovering from posix semaphores, which are used by boost on linux),
but I couldn't find any answers. Lars had asked this here also, almost
an year ago but no answers in that thread either. This seems like a
basic issue but am totally lost on how to even approach it.

Sachin Garg


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