comp.lang.ada
 help / color / mirror / Atom feed
From: ka@hiway1.exit109.com (Kenneth Almquist)
Subject: Re: Ada Protected Object Tutorial #1
Date: 1999/12/24
Date: 1999-12-24T05:27:45+00:00	[thread overview]
Message-ID: <83v08h$f2o$1@news1.exit109.com> (raw)
In-Reply-To: 385984BC.1FB1@hello.nl

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3290 bytes --]

Karel Th�nissen <thoenissen@hello.nl> wrote:
> I am wondering whether there is a clean solution to the problem that Mr
> Kylheku presented: how can we combine several protected type services
> into one transaction-like construct without requiring clairvoyance or
> retrofitting.

One approach is to have the client perform the locking, and to specify
an interface to the object which forces the client to lock the object
before performing any other operations on it.  E.g.:

    package Object_Package is

        type Object is limited private;
        type Object_Ptr is access all Obj;
            -- Object is the type of the objects we want to protect.

        type Object_Handle is limited private;
            -- An Object_Handle is used to refer to an Object.  Only one
            -- Object_Handle is allowed to refer to a given object at
            -- any one time, so if you have an Object_Handle referring
            -- to an Object, you can safely operate on that Object
            -- without worrying about another task modifying the
            -- Object.

        procedure Set_Handle(Handle : Object_Handle, Obj : Object_Ptr);
            -- If Obj is not null, then this routine will make Handle
            -- refer to the specified Object.  If another Object_Handle
            -- current refers to the Object, then this routine will
            -- block until that is no longer the case.
            --
            -- Since only one Object_Handle can refer to an Object at
            -- any one time, when you are done using an Object, you
            -- should make the Object_Handle stop referring to it,
            -- either by calling Set_Handle with the Obj parameter
            -- set to null, or by destroying the Object_Handle.

        procecure Op_1(Handle : Object_Handle);
        procecure Op_2(Handle : Object_Handle);
            -- These are operations which apply to Objects.  To call them,
            -- you pass an Object_Handle rather than an Object.  This
            -- ensures that two tasks cannot perform an operation on the
            -- same object at the same time.

        procedure Op_1(Obj : Object_Ptr);
            -- This is a convenience function, intended to be used when
            --  you only want to perform a single Op_1 on an object.  It
            -- is equivalent to:
            --
            --     procedure Op_1(Obj : Object_Ptr) is
            --         Handle : Object_Handle;
            --     begin
            --         Set_Handle(Handle, Obj);
            --         Op_1(Handle);
            --     end Op_1;

    end Object_Package;

Object is implemented as a protected type, and includes Lock and Unlock
operations.  An Object_Handle is a record containing an Object_Ptr.
Set_Handle unlocks the Object currently pointed to by the Object_Handle
(unless the handle is null), and locks the new Object (unless the new
Object_Ptr is null).  Object_Handle is implemented as a controlled type,
so that the Object it refers to can be freed when the handle is destroyed.

The second version of Op_1 can be implemented as shown in the specification,
but it may be more efficient to have it call a protected entry whose
barrier condition specifies that the semaphore is unlocked.
				Kenneth Almquist




  parent reply	other threads:[~1999-12-24  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       ` Mike Silva
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-24  0:00       ` Kenneth Almquist [this message]
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               ` 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               ` 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
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