From: "J . A . Magallon" <jamagallon@able.es>
To: Rogier Wolff <R.E.Wolff@BitWizard.nl>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Semaphores slow???
Date: Wed, 27 Dec 2000 17:48:21 +0100 [thread overview]
Message-ID: <20001227174821.C1038@werewolf.able.es> (raw)
In-Reply-To: <20001227162655.A783@werewolf.able.es> <200012271545.QAA18971@cave.bitwizard.nl>
In-Reply-To: <200012271545.QAA18971@cave.bitwizard.nl>; from R.E.Wolff@BitWizard.nl on Wed, Dec 27, 2000 at 16:45:29 +0100
On 2000.12.27 Rogier Wolff wrote:
> J . A . Magallon wrote:
>
> You missed that we push the bs 1000 times before we allow the producer
> to start.
>
Lets rename
write_buffer_sem == holes
write_sem == items
So:
producer:
while (1) {
// Wait a hole
sem_wait (&holes);
...
// Signal we posted an item
sem_post (&items);
}
consumer:
for (i=0;i<1000;i++)
sem_post (&holes);
/* OK, you have 1000 holes fo fill */
while (1) {
// Wait an item
sem_wait (&items);
...
// Say we left a hole
sem_post (&holes);
}
So you have a finite FIFO of size N, empty at start. There will be
a short transient state when:
- if producer is faster, queue fills; consumer is 'free-run'-alike,
there is always something to eat, but producer blocks him.
- if consumer is faster, queue exhausts and it runs as if queue size
was 1. There is always hole for a new item, but consumer has to wait
a full producer loop to get an item.
And you end up in the case of the previous post.
You don't have to keep the queue blocked while you work on items.
Try something like:
producer:
while (1) {
... (prepare item)
(and consumer can read items at the same time)
// Wait a hole
sem_wait (&holes);
put item
// Signal we posted an item
sem_post (&items);
}
consumer:
for (i=0;i<1000;i++)
sem_post (&holes);
/* OK, you have 1000 holes fo fill */
while (1) {
// Wait an item
sem_wait (&items);
get item
// Say we left a hole
sem_post (&holes);
... (use item)
(and producer can insert items at the same time)
}
--
J.A. Magallon $> cd pub
mailto:jamagallon@able.es $> more beer
Linux werewolf 2.2.19-pre3-aa3 #3 SMP Wed Dec 27 10:25:32 CET 2000 i686
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
next prev parent reply other threads:[~2000-12-27 17:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-12-27 14:15 Semaphores slow??? Rogier Wolff
2000-12-27 15:26 ` J . A . Magallon
[not found] ` <200012271545.QAA18971@cave.bitwizard.nl>
2000-12-27 16:48 ` J . A . Magallon [this message]
2000-12-28 12:27 ` Davide Libenzi
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=20001227174821.C1038@werewolf.able.es \
--to=jamagallon@able.es \
--cc=R.E.Wolff@BitWizard.nl \
--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.