Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

semop and SEM_UNDO

72 views
Skip to first unread message

Rafal Dabrowa

unread,
Oct 14, 2004, 6:18:00 AM10/14/04
to

In semop man page I have found in BUGS section the following explanations:

<quote>
When a process terminates, its set of associated semadj structures is used
to undo the effect of all of the semaphore operations it performed with
the SEM_UNDO flag. This raises a difficulty: if one (or more) of these
semaphore adjustments would result in an attempt to decrease a
semaphore's value below zero, what should an implementation do? One
possible approach would be to block until all the semaphore adjustments
could be performed. This is however undesirable since it could force
process termination to block for arbitrarily long periods. Another
possibility is that such semaphore adjustments could be ignored
altogether (somewhat analogously to failing when IPC_NOWAIT is specified
for a semaphore operation). Linux adopts a third approach: decreasing the
semaphore value as far as possible (i.e., to zero) and allowing
process termination to proceed immediately.
</quote>

I have found fourth approach: semop() should fail if the operation would
result with semadj value less than new semaphore value. This may occur only
when semop() attempts to decrease semaphore value without SEM_UNDO flag
set.

What do you think about this approach ? In my opinion it is the best one. If
so, why is it not implemented ? Does anybody see something wrong there ?


Rafal
--
sed -e s/s/a/g <my_address >my_right_address

Michael Kerrisk

unread,
Oct 15, 2004, 4:26:34 AM10/15/04
to
On Thu, 14 Oct 2004 12:18:00 +0200, Rafal Dabrowa
<rdsb...@poczts.onet.pl> wrote:

>
>In semop man page I have found in BUGS section the following explanations:
>
><quote>
>When a process terminates, its set of associated semadj structures is used
>to undo the effect of all of the semaphore operations it performed with
>the SEM_UNDO flag. This raises a difficulty: if one (or more) of these
>semaphore adjustments would result in an attempt to decrease a
>semaphore's value below zero, what should an implementation do? One
>possible approach would be to block until all the semaphore adjustments
>could be performed. This is however undesirable since it could force
>process termination to block for arbitrarily long periods. Another
>possibility is that such semaphore adjustments could be ignored
>altogether (somewhat analogously to failing when IPC_NOWAIT is specified
>for a semaphore operation). Linux adopts a third approach: decreasing the
>semaphore value as far as possible (i.e., to zero) and allowing
>process termination to proceed immediately.
></quote>
>
>I have found fourth approach: semop() should fail if the operation would
>result with semadj value less than new semaphore value. This may occur only
>when semop() attempts to decrease semaphore value without SEM_UNDO flag
>set.

This isn't workable. Other processes may be adjusting the semaphore
also. So any combination of [semadj] and [current semaphore value]
could be legitimate.

Cheers,

Michael

0 new messages