From: Manfred Spraul <manfred@colorfullife.com>
To: John M Collins <jmc@xisl.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Semaphores and threads anomaly and bug?
Date: Tue, 04 Nov 2003 18:59:19 +0100 [thread overview]
Message-ID: <3FA7E8F7.7060304@colorfullife.com> (raw)
John wrote:
>I know this isn't defined anywhere but the seems to be an ambiguity and
>discrepancy between versions of Unix and Linux over threads and semaphores.
>
>Do the "SEM_UNDO"s get applied when a thread terminates or when the
>"whole thing" terminates?
>
>
According to the Unix spec: per-process.
Older Linux kernels applied it per-thread. Newer kernels can handle it
per-process, and AFAIK it's the default for NPTL.
>I think that in ipc/sem.c line 1062 the line should be made
>conditional on "u->semadj[i]" being non-zero.
>
>
Fixed in 2.6. But there is another bug in that block: undos can increase
the semaphore value above SEMVMX.
>There is a potential problem here in that the code in ipc/sem.c doesn't
>allow the adjustment to yield a negative value but what if it starts at
>zero, thread A increments it, thread B decrements it back to zero (both
>with SEM_UNDO) and thread A exits first? Thread A's undo won't work and
>then thread B's undo will increment it again leaving it in an incorrect
>state which is different from thread B exiting first.
>
>
Correct. undo operations should never try to decrease the semaphore
value - an attempt to decrease below 0 is either silently ignored, or
the semaphore value is set to 0.
--
Manfred
next reply other threads:[~2003-11-04 17:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-04 17:59 Manfred Spraul [this message]
-- strict thread matches above, loose matches on Subject: below --
2003-11-04 16:45 Semaphores and threads anomaly and bug? John M Collins
2003-11-04 17:29 ` Linus Torvalds
2003-11-04 18:09 ` John M Collins
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3FA7E8F7.7060304@colorfullife.com \
--to=manfred@colorfullife.com \
--cc=jmc@xisl.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.