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: <slrn85npi1.4ps.kaz@ashi.FootPrints.net> (raw)
In-Reply-To: 86aen9z7qi.fsf@ppp-111-13.villette.club-internet.fr

On 17 Dec 1999 20:29:25 +0100, Laurent Guerby <guerby@acm.org> wrote:
>Karel Th�nissen <thoenissen@hello.nl> writes:
>> [...] He noticed that protected types are great if the caller
>> needs a single service from the protected type, but they are not that
>> great if you need more than one service from the same protected type.
>> Not only does the protected type solution require locking and unlocking
>> for every single service invocation, instead of one pair for the whole
>> deal, it also cannot avoid the situation that other tasks are serviced
>> in between two calls. 
>
>This claim is wrong, when you're inside a protected procedure, calls
>to other protected procedure on the same object are done
>without locking of course.

This requires the procedures to be passed information about whether the
object is locked by this thread or not. For example, a hidden parameterr.
In C++-like pseudocode, this might look like:

    void object::frobnicate(bool already_locked = false)
    {
	if (!already_locked);
	    lock();

	// frobnicate

	if (!already_locked)
	    unlock();
    }

That is overhead. Another thing that is possible is that the compiler might
generate two function images: one that assumes the lock and one that does not.
When a protected procedure calls another one for the same object, the compiler
will generate a call to the variant which does not acquire the lock. 

These solution requires some measure of clairvoyance: what if the protected
procedure calls into another subsystem which then calls back into a protected
procedure on the same object? How do you pass the ``already_locked'' knowledge
across calls to foreign subsystems?

The solution is probably to use recursive locks, which check the ID of the
calling against an ownership ID stored in the lock. Recursive locks are
slightly inefficient because they have to retrieve the ID of the current thread
and compare it.




  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         ` Kaz Kylheku [this message]
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-18  0:00         ` Karel Th�nissen
1999-12-18  0:00           ` Laurent Guerby
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   ` Tucker Taft
1999-12-18  0:00     ` Kaz Kylheku
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               ` Laurent Guerby
1999-12-19  0:00               ` Robert Dewar
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-17  0:00     ` Vladimir Olensky
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