asymmetric usage of SysV semaphore, SEM_UNDO
asymmetric usage of SysV semaphore, SEM_UNDO
- Subject: asymmetric usage of SysV semaphore, SEM_UNDO
- From: "Alex Sheh" <email@hidden>
- Date: Mon, 16 Jan 2006 17:47:00 -0800
- Thread-topic: asymmetric usage of SysV semaphore, SEM_UNDO
Hi all,
Through googling I’ve seen some warnings against
using SysV semaphore’s SEM_UNDO flag for asymmetric semaphores – i.e. Process A
acquires sem1 and ProcessB releases sem1. I can see the problem when one process
exits before the other. For instance in the usage case where Process A is
sitting on an acquire operation waiting for Process B to release the semaphore -
if ProcessB releases sem1 and exits before ProcessA acquires sem1, then upon
exit ProcessB will acquire sem1 via SEM_UNDO (opposite of release), and "steal"
it before ProcessA has a chance to grab sem1.
However, if Process A and B are expected to exit at
the same time, then it doesn’t seem like this should be an issue. Even if either
Process A or B exit abnormally, as long as we terminate the remaining process
(which could possibly be hung), then the SEM_UNDO flag (set for acquire and
release ops) would result in the semaphore value being rolled back via undo to
its initial value, say zero. So when Process A and B are launched again, their
semaphore value should start out at zero, and allow for proper synchronization
(hopefully). As long as the processes are terminated and launched again, I don’t
see the possibility of a corrupt semaphore value in the system.
Am I missing something here? I’ve come across
warnings against asymmetric usage of SysV semaphore’s SEM_UNDO operation, so I’m
quite cautious about using it. But if my above analysis is correct, in the
context of my particular needs (processes are expected to exit at same time, and
recovery involves terminating all remaining processes and re-launching all
process), does it seem okay to use them? What exactly is the major problem case
when using asymmetric, SysV, and SEM_UNDO? Is the behavior platform-specific (my
apps are running on MacOSX, but I’m curious because I read that the Linux
implementation prevents SEM_UNDO from decrementing a sem value past zero, which would be problematic for my needs since this could corrupt the semaphore
value)? Thank you kindly for
your help. If another mailing list is more
appropriate for this question, please let me know.
-
Alex
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden