From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,d87fcae02ce5c10a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Synchronizing on multiple distinict resources Date: Fri, 20 Aug 2004 10:59:41 +0200 Message-ID: References: <7ebaa24d.0408021054.4abc6e73@posting.google.com> <782e906e.0408101051.5e122af0@posting.google.com> <1f4ugyz3ig9rc$.785e2wqt1qyg$.dlg@40tude.net> <782e906e.0408191418.75299957@posting.google.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de IQNULu9ziMNtWOqkUVFt/g7jXOq0/xv2i5iAQWbKnCOBJ1QJ8= User-Agent: 40tude_Dialog/2.0.12.1 Xref: g2news1.google.com comp.lang.ada:2887 Date: 2004-08-20T10:59:41+02:00 List-Id: On 19 Aug 2004 15:18:44 -0700, Chad R. Meiners wrote: > "Dmitry A. Kazakov" 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