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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: How to: communication between multiple tasks using protected objects - with no polling? Date: Wed, 21 Jan 2015 08:11:32 +0000 Organization: A noiseless patient Spider Message-ID: References: <32208488-3a04-4d2a-8c64-840502dcf96d@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="8878eaae66d49f7d529ec3c7abf78fb7"; logging-data="17178"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mlJ9s3XyfuWERrGPsRco88/L/2Q6EcEE=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) Cancel-Lock: sha1:7KR/942cKJ4C4ZAApDLPAbcR+iM= sha1:QMQp4emFIXJeBUqKUjnXaFYM5DE= Xref: news.eternal-september.org comp.lang.ada:24661 Date: 2015-01-21T08:11:32+00:00 List-Id: Jeffrey Carter writes: > Another approach might be > > type Q_ID is (Q1, Q2, ...); > > type Q_Item (Q : Q_ID := Q_ID'First) is record > case Q is > when Q1 => > Item_1 : Q1_Item; > when Q2 => > Item_2 : Q2:Item; > ... > end case; > end record; > > protected Qs is > entry Get (Item : out Q_Item); > private -- Qs > Q_1 : Q1_Q; > Q_2 : Q2_Q; > ... > end Qs; > > 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 := (Q => Q1, Item_1 => Q_1.Get); > elsif not Q_2.Is_Empty then > item := (Q => Q2, Item_2 => Q_2.Get; > ... > end if; > end Get; > end Qs; Yet another approach: make Q_Item an abstract tagged type with an abstract Handle operation. You'd need the actual queue inside the PO to be of Q_Item'Class (or perhaps an access to such, in which case you'd need to do your own deallocation).