comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Synchronizing on multiple distinict resources
Date: Fri, 20 Aug 2004 10:59:41 +0200
Date: 2004-08-20T10:59:41+02:00	[thread overview]
Message-ID: <r7dtg341mrwm.1qu2oi5n4cylu$.dlg@40tude.net> (raw)
In-Reply-To: 782e906e.0408191418.75299957@posting.google.com

On 19 Aug 2004 15:18:44 -0700, Chad R. Meiners wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message news:<1f4ugyz3ig9rc$.785e2wqt1qyg$.dlg@40tude.net>...
>>>> 1. multiple protected actions / rendezvous (to queue to two chopsticks)
>>> 
>>> Perhaps something like 
>>> 
>>> procedure Eat(Left, Right : in out Chop_Stick) is
>>>   Synchronize Left and Right;  -- Exclusive access until end of
>>> procedure
>>> begin
>>>   ...
>>> end Eat;
>> 
>> One could allow "free" entry points with normal syntax:
>> 
>> protected type Chop_Stick is
>>    procedure Release; -- A "member" procedure
>> private
>>    Free : Boolean;
>> end Chop_Stick;
>>    -- This is not Ada
>> entry Seize (Left, Right : in out Chop_Stick);
>>    -- Not a "member", but still a primitive operation
>> 
>> entry Seize (Left, Right : in out Chop_Stick)
>>    when Left.Free and Right.Free is
>>       -- Dispatching parameters are allowed to appear in barriers
>> begin
>>    Left.Free  := False;
>>    Right.Free := False;
>> end Seize;

> I think that the when clause isn't even needed since it would need
> exclusive access to both left and right.   The question becomes
> whether this syntax breaks the encapsulation of the protected types.

Yes it does. The syntax I used was of course imaginary. The problem you
mentioned arise because protected types fall out of standard Ada visibility
rules based on packages. With packages one has an advantage to see private
parts of many things simultaneously. Protected objects rather mimic C++,
which approaches the problem by its nasty "friend"s. I hate to see
something like that in Ada. I would rather allow primitive operations to
look into the private parts of dispatching parameters.

BTW the solution (2) based on multiple inheritance will have no such
problem. But it has another. One could access private parts of
non-dispatching (alien) parameters:

type protected Pair is new Left, Right : Chop_Stick with null record;

procedure Criminal (Baz : Pair; Victim : Chop_Stick'Class) is
begin
   Victim.Free := True;
end Criminal;

This should be made illegal.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



      reply	other threads:[~2004-08-20  8:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-02 18:54 Synchronizing on multiple distinict resources Chad R. Meiners
2004-08-02 21:48 ` Jim Rogers
2004-08-03  8:56 ` Dmitry A. Kazakov
2004-08-10 18:51   ` Chad R. Meiners
2004-08-11 13:52     ` Dmitry A. Kazakov
2004-08-19 22:18       ` Chad R. Meiners
2004-08-20  8:59         ` Dmitry A. Kazakov [this message]
replies disabled

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