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 X-Received: by 10.52.167.129 with SMTP id zo1mr20516694vdb.2.1411318838077; Sun, 21 Sep 2014 10:00:38 -0700 (PDT) Path: border1.nntp.dca1.giganews.com!nntp.giganews.com!dc16no66300qab.1!news-out.google.com!rp1ni5262igb.0!nntp.google.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!fx16.iad.POSTED!not-for-mail From: Brad Moore User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Simp,e example for 2 tasks References: <9b22dd09-6137-4f4b-8be1-28255032df70@googlegroups.com> In-Reply-To: <9b22dd09-6137-4f4b-8be1-28255032df70@googlegroups.com> Message-ID: NNTP-Posting-Host: 68.145.219.148 X-Complaints-To: internet.abuse@sjrb.ca X-Trace: 1411318837 68.145.219.148 (Sun, 21 Sep 2014 17:00:37 UTC) NNTP-Posting-Date: Sun, 21 Sep 2014 17:00:37 UTC Date: Sun, 21 Sep 2014 11:00:37 -0600 X-Received-Bytes: 3895 X-Received-Body-CRC: 2442332209 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Original-Bytes: 3813 Xref: number.nntp.dca.giganews.com comp.lang.ada:189074 Date: 2014-09-21T11:00:37-06:00 List-Id: On 2014-09-21 7:31 AM, Stribor40 wrote: > Would anyone be able to post simple example of ada program showing 2 tasks taking to each other please. For example one task sends message to another saying "hi" and second taks replying "hi back". > I am having troubles finding example of simple program like this online > As others have mentioned, the problem needs to be better specified. My assumptions are; 1. No content to the message, as none is needed, so no parameters are needed for the entry calls 2. The sender and listener tasks are tightly coupled and know of each other, so can send message to each other directly. 3. The listener needs to send back a separate message to the sender. In other words, the response message is not sent as part of the rendezvous, and is sent separately. Dmitry's example handles the other case where only one rendezvous is needed. procedure Task_Example is task Listener is entry Send_Message; end Listener; task Sender is entry Give_Reply; end Sender; task body Listener is begin accept Send_Message; Put_Line ("Sender says Hi"); Sender.Give_Reply; end Listener; task body Sender is begin Listener.Send_Message; accept Give_Reply; Put_Line ("Listener says Hi Back!"); end Sender; begin null; end Task_Example; The task communication here is via task rendezvous. For a more complicated example, I might have chosen to use a protected object to handle the communication instead. I generally prefer to use protected objects for task communication, over rendezvous. procedure Task_Example is protected Manager is procedure Send_Message; entry Wait_For_Message; procedure Send_Response; entry Wait_For_Response; private Received_Message : Boolean := False; Received_Response : Boolean := False; end Manager; protected body Manager is procedure Send_Message is begin Received_Message := True; end Send_Message; entry Wait_For_Message when Received_Message is begin null; end Wait_For_Message; procedure Send_Response is begin Received_Response := True; end Send_Response; entry Wait_For_Response when Received_Response is begin null; end Wait_For_Response; end Manager; task Listener; task Sender; task body Listener is begin Manager.Wait_For_Message; Put_Line ("Sender says Hi"); Manager.Send_Response; end Listener; task body Sender is begin Manager.Send_Message; Manager.Wait_For_Response; Put_Line ("Listener says Hi Back!"); end Sender; begin null; end Task_Example; Brad