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: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: How to: communication between multiple tasks using protected objects - with no polling? Date: Tue, 20 Jan 2015 17:47:26 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <32208488-3a04-4d2a-8c64-840502dcf96d@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Wed, 21 Jan 2015 00:46:58 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="7519078e121dffe718f7ef9b6511f660"; logging-data="18026"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+1m7ABWBbx++fLAz+yY4KO2NUN70EtcZ4=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 In-Reply-To: <32208488-3a04-4d2a-8c64-840502dcf96d@googlegroups.com> Cancel-Lock: sha1:TxyZaDm4RV/MfYGSIabIre+h8wg= Xref: news.eternal-september.org comp.lang.ada:24658 Date: 2015-01-20T17:47:26-07:00 List-Id: On 01/20/2015 03:36 PM, Esa Riihonen wrote: > > The C-program consists of various Linux processes that communicate with each > other mainly through FIFO's. It seems natural to implement the process > functionality as Ada tasks. As the inter task communication I decided to try > protected types (instead of task entries). 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 best choice. > Am I missing something? Or have my though processes been totally corrupted by > too much (forced) C during the decades - and thus I'm trying to do something > silly and dangerous? You can do select PO1.Get (...); then abort PO2.Get (...); end select; This might, however, result in both entries being executed. 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; if your system is actually many tasks adding items to queues and one waiting for something on one of those queues, then it might be best to have the waiting task have entries, and put forwarder tasks between the queues and the waiting task. -- 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