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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.42.22.145 with SMTP id o17mr33417794icb.17.1421860564086; Wed, 21 Jan 2015 09:16:04 -0800 (PST) X-Received: by 10.140.97.200 with SMTP id m66mr2174qge.42.1421860563998; Wed, 21 Jan 2015 09:16:03 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!h15no1379681igd.0!news-out.google.com!l7ni0qai.0!nntp.google.com!bm13no2087948qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 21 Jan 2015 09:16:03 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=80.223.109.117; posting-account=xMk30AoAAACEWgBjdZfjW9cEqRCtnf-j NNTP-Posting-Host: 80.223.109.117 References: <32208488-3a04-4d2a-8c64-840502dcf96d@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: How to: communication between multiple tasks using protected objects - with no polling? From: Esa Riihonen Injection-Date: Wed, 21 Jan 2015 17:16:04 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 4206 X-Received-Body-CRC: 4055736795 Xref: news.eternal-september.org comp.lang.ada:24670 Date: 2015-01-21T09:16:03-08:00 List-Id: keskiviikko 21. tammikuuta 2015 2.47.29 UTC+2 Jeffrey Carter kirjoitti: ... snip ... > You should also revisit your design in light of Ada tasking capabilities.= The > choice of multiple tasks that communicate through queues may not be the b= est choice. That is totally correct. ... snip ... > You can do >=20 > select > PO1.Get (...); > then abort > PO2.Get (...); > end select; >=20 > This might, however, result in both entries being executed. If I understand correctly this will indeed work when selecting between two = PO entries. And it wouldn't matter if both got executed (although I just no= w can't see how this could happen). However, there seems not to be a natura= l way to expand this for more than those two. This seems to be syntacticall= y correct (compiles): select PO1.Get (...); then abort select PO2.Get (...); then abort PO3.Get (...); end select end select; But I'm not sure whether it would actually do what I want it to do. That is= : suspend there until any of the entry barriers becomes true and then exit = the whole outermost select statement? Even if it works I have a (minor) concern that it is not 'pretty' as it doe= sn't reflect the mutual equality of the entries - and thus has a feel of 'h= ack' there ;) > Another approach might be >=20 > type Q_ID is (Q1, Q2, ...); >=20 > type Q_Item (Q : Q_ID :=3D Q_ID'First) is record > case Q is > when Q1 =3D> > Item_1 : Q1_Item; > when Q2 =3D> > Item_2 : Q2:Item; > ... > end case; > end record; >=20 > protected Qs is > entry Get (Item : out Q_Item); > private -- Qs > Q_1 : Q1_Q; > Q_2 : Q2_Q; > ... > end Qs; >=20 > protected body Qs is > entry Get (Item : out Q_Item) when > not Q_1.Is_Empty or not Q_2.Is_Empty or ... > is > -- Empty declarative part > begin -- Get > if not Q_1.Is_Empty then > Item :=3D (Q =3D> Q1, Item_1 =3D> Q_1.Get); > elsif not Q_2.Is_Empty then > item :=3D (Q =3D> Q2, Item_2 =3D> Q_2.Get; > ... > end if; > end Get; > end Qs; Thanks for that! I'm not sure I did understand it thoroughly at first readi= ng though I did say that I did read 'the book' - but surely it didn't all s= ink in in the first reading ;) > if your system is actually many tasks adding items to queues and one wait= ing for > something on one of those queues, then it might be best to have the waiti= ng task > have entries, and put forwarder tasks between the queues and the waiting = task. 'Forwarder tasks' - definitely might be something I will study at this stag= e. Thanks a lot. > --=20 > Jeff Carter > "Ada has made you lazy and careless. You can write programs in C that > are just as safe by the simple application of super-human diligence." > E. Robert Tisdale > 72 I really like the Tisdale quote - gonna steal it ;)