From: Bob Miller <rem@osdl.org>
To: "Edward Shao (ªòªv°ê)" <szg90@cs.ccu.edu.tw>
Cc: linux-kernel@vger.kernel.org
Subject: Re: a question about __down() in Linux/arch/i386/kernel/semaphore.c
Date: Mon, 5 Aug 2002 09:37:43 -0700 [thread overview]
Message-ID: <20020805093743.A9689@doc.pdx.osdl.net> (raw)
In-Reply-To: <024c01c23c8e$5804d710$74667b8c@edward>; from szg90@cs.ccu.edu.tw on Mon, Aug 05, 2002 at 10:42:37PM +0800
On Mon, Aug 05, 2002 at 10:42:37PM +0800, Edward Shao \(ªòªv°ê\) wrote:
> sorry, i found it!
> wake_up_locked(&sem->wait);
> but why do we need to wake up the sleepers again?
> Thank you very much.
>
> -Edward Shao-
>
> ----- Original Message -----
> From: "Edward Shao (ªòªv°ê)" <szg90@cs.ccu.edu.tw>
> To: <linux-kernel@vger.kernel.org>
> Sent: Monday, August 05, 2002 10:33 PM
> Subject: a question about __down() in Linux/arch/i386/kernel/semaphore.c
>
>
> > Hi,
> >
> > I have a question about __down() in kernel 2.4.18
> > (Linux/arch/i386/kernel/semaphore.c)
> > I found the last line of __down() is
> > wake_up(&sem->wait);
> > but in kernel 2.5.28, i didn't see this line..
> > is this line necessary in kernel 2.4.18?
> > why?
> >
> > Thank you very much.
> >
> > Best Regard!!!
> >
> > -Edward Shao-
> >
> >
The quick answer: so we don't miss waking someone up. But, seriously,
the semaphore code is very subtle.
This semaphore implementation allows more than one process to be in the
critical section at a time (a.k.a. a counting semaphore). In order to
support those semantics, more than one wakeup may occur before a process
is pulled off the wake_q and changed to running. Because the process that
is waiting to run (in the __down() code) is responsible for pulling itself
off the wait_q, if the 2 __up()s happen before the __down() can finish,
the 2 __up()s will wakeup the same process twice. So, the __down() code
needs to protect agaist this.
--
Bob Miller Email: rem@osdl.org
Open Source Development Lab Phone: 503.626.2455 Ext. 17
prev parent reply other threads:[~2002-08-05 16:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-05 14:33 Edward Shao \(邵治國\)
2002-08-05 14:42 ` Edward Shao \(邵治國\)
2002-08-05 16:37 ` Bob Miller [this message]
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=20020805093743.A9689@doc.pdx.osdl.net \
--to=rem@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=szg90@cs.ccu.edu.tw \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®