From: Stelian Pop <stelian.pop@fr.alcove.com>
To: Nigel Gamble <nigel@nrg.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Use semaphore for producer/consumer case...
Date: Mon, 26 Mar 2001 16:52:23 +0200 [thread overview]
Message-ID: <20010326165223.F15689@come.alcove-fr> (raw)
In-Reply-To: <20010323130722.A8916@come.alcove-fr> <Pine.LNX.4.05.10103231541010.6461-100000@cosmic.nrg.org>
In-Reply-To: <Pine.LNX.4.05.10103231541010.6461-100000@cosmic.nrg.org>; from nigel@nrg.org on Fri, Mar 23, 2001 at 03:52:54PM -0800
On Fri, Mar 23, 2001 at 03:52:54PM -0800, Nigel Gamble wrote:
> For the producer/consumer case, you want to initialize the semaphore to
> 0, not 1 which DECLARE_MUTEX(sem) does. So I would use
>
> __DECLARE_SEMAPHORE_GENERIC(sem, 0)
You're right that the DECLARE_MUTEX does not (entirely) do the job,
but I set manually the value of sem->count:
> > atomic_set(&sem->count, -10);
> Then consumer could be:
> /* Wait for 10 items to be produced */
> for (i = 0; i < 10; i++)
> down(&sem);
IMHO, this will not work, because the producer could be issuing
more than one 'up(&sem)' at the time...
Stelian.
--
Stelian Pop <stelian.pop@fr.alcove.com>
|------------- Ingénieur Informatique Libre --------------|
| Alcôve - http://www.alcove.com - Tel: +33 1 49 22 68 00 |
|----------- Alcôve, l'informatique est libre ------------|
next prev parent reply other threads:[~2001-03-26 14:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-03-23 12:07 Stelian Pop
2001-03-23 23:52 ` Nigel Gamble
2001-03-26 14:52 ` Stelian Pop [this message]
2001-03-23 18:34 Manfred Spraul
2001-03-26 14:54 ` Stelian Pop
2001-03-26 17:12 ` Manfred Spraul
2001-03-27 7:57 ` Stelian Pop
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=20010326165223.F15689@come.alcove-fr \
--to=stelian.pop@fr.alcove.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nigel@nrg.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 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®