comp.lang.ada
 help / color / mirror / Atom feed
From: kaz@ashi.footprints.net (Kaz Kylheku)
Subject: Re: Ada Protected Object Tutorial #1
Date: 1999/12/18
Date: 1999-12-18T00:00:00+00:00	[thread overview]
Message-ID: <slrn85nr62.4ps.kaz@ashi.FootPrints.net> (raw)
In-Reply-To: 385AC716.7E65BD5C@averstar.com

On Fri, 17 Dec 1999 23:28:22 GMT, Tucker Taft <stt@averstar.com> wrote:
>Trying to provide this same capability via an "API"
>is quite awkward, as it requires the programmer to bundle up an operation and
>"submit" it along with some kind of boolean function, and allow the
>underlying run-time system decide who evaluates the boolean function
>and who executes the operation.  Almost all APIs instead are set up
>so that the programmer's code evaluates the boolean condition outside
>of the run-time system, and must do so repeatedly each time control
>returns to the user's code, to ensure that the boolean is true by
>at the moment when the user's code gets control.  This can result

This is practical. The condition variable wait might be done inside a
protected kernel. It would be impractical to have, say, a UNIX kernel
call back into application code to determine if some predicate is true.

>in even more unnecessary context switches, and/or bugs if the
>programmer neglects to build the evaluation of the boolean condition
>into a loop around the condition-variable "wait" operation.

That loop around a condition variable wait is needed to resolve
spurious wakeups and race conditions. The logic gives more ways to
the implementor to provide a correct implementation.

Suppose your thread is waiting on a condition, and the condition is signalled.
It's time to reacquire the monitor (or mutex). But a thread running on another
CPU grabs it first and changes the object so that the condition the original
thread waited for is no longer valid.

I believe that providing guarantees against this sort of occurence introduces
overhead; that is, the cure may be worse than the ailment, particularly
on multiprocessors.

>As one data point, a classic producer/consumer example with a
>bounded buffer, when coded using a protected type versus using
>mutex/condition variables, results in typically half as many
>locks and unlocks, and one third as many context switches between
>the producer and the consumer.  The mutex/condition variable
>approach involves so much more work because each thread ends up
>doing all the work "itself," rather than allowing the other thread
>to do a little bit of work on its behalf while it already holds the lock.

Is there a paper about this which argues the case in more detail?




  reply	other threads:[~1999-12-18  0:00 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-15  0:00 Ada Protected Object Tutorial #1 James S. Rogers
1999-12-16  0:00 ` Kaz Kylheku
1999-12-16  0:00   ` John English
1999-12-16  0:00     ` Ed Falis
1999-12-16  0:00       ` Usenet Poster Boy
1999-12-17  0:00     ` Karel Th�nissen
1999-12-17  0:00       ` Laurent Guerby
1999-12-18  0:00         ` Karel Th�nissen
1999-12-18  0:00           ` Laurent Guerby
1999-12-18  0:00         ` Kaz Kylheku
1999-12-18  0:00           ` Laurent Guerby
1999-12-18  0:00             ` Kaz Kylheku
1999-12-19  0:00               ` Laurent Guerby
1999-12-20  0:00                 ` Stanley R. Allen
1999-12-21  0:00               ` Robert I. Eachus
     [not found]             ` <33qr5scnbs04v391ev4541p5bv48hklg3q@4ax.com>
1999-12-20  0:00               ` Robert A Duff
1999-12-18  0:00           ` Robert A Duff
1999-12-18  0:00             ` Kaz Kylheku
1999-12-17  0:00       ` Mike Silva
1999-12-24  0:00       ` Kenneth Almquist
1999-12-16  0:00   ` James S. Rogers
1999-12-17  0:00     ` Laurent Guerby
1999-12-17  0:00   ` Robert A Duff
1999-12-17  0:00     ` Vladimir Olensky
1999-12-17  0:00   ` Tucker Taft
1999-12-18  0:00     ` Kaz Kylheku [this message]
1999-12-18  0:00       ` Robert A Duff
1999-12-18  0:00         ` Kaz Kylheku
1999-12-19  0:00           ` swhalen
1999-12-19  0:00             ` Kaz Kylheku
1999-12-19  0:00               ` Robert Dewar
1999-12-19  0:00               ` Laurent Guerby
1999-12-20  0:00       ` Vladimir Olensky
1999-12-26  0:00         ` Ehud Lamm
1999-12-26  0:00           ` Robert Dewar
1999-12-26  0:00             ` Kaz Kylheku
1999-12-27  0:00               ` Robert Dewar
1999-12-27  0:00                 ` Richard D Riehle
1999-12-27  0:00                   ` Robert Dewar
1999-12-31  0:00                     ` Richard D Riehle
1999-12-27  0:00                 ` Jean-Pierre Rosen
1999-12-27  0:00               ` Robert Dewar
2000-01-02  0:00             ` Tucker Taft
1999-12-17  0:00 ` Robert A Duff
1999-12-18  0:00   ` Kaz Kylheku
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox