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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: border1.nntp.dca1.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!newsfeed.tele2net.at!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Simp,e example for 2 tasks Date: Sun, 21 Sep 2014 18:09:27 +0200 Organization: cbb software GmbH Message-ID: <17mfa3tl60vaq$.1smp65wtk6b9j$.dlg@40tude.net> References: <9b22dd09-6137-4f4b-8be1-28255032df70@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: ZB2Fb2q1fa4xpMpNKFqV6Q.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: number.nntp.dca.giganews.com comp.lang.ada:189072 Date: 2014-09-21T18:09:27+02:00 List-Id: On Sun, 21 Sep 2014 06:31:28 -0700 (PDT), 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 Because there are problems with that: 1. It is bad design, tight coupling. There should never be so that two object knew each other. Only one task may know another, e.g. client knows server, server does not know any clients. 2. Sending messages is not the method of task communication. Tasks have entry points which are alike to procedures not raw data (messages). 3. Messages as marshaled parameters of some asynchronous requests are not implemented using tasks. There are protected objects which serve this purpose in Ada. 4. It is not clear what sort of communication you want. Your description misses many crucial design details required. E.g. are parameters (messages) marshaled, is exchange synchronous, how knows whom etc. Anyway, here is an example of text exchange between two tasks A and B: with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Text_IO; use Ada.Text_IO; procedure Talk is task A is entry Ask (Message : in out Unbounded_String); end A; task B is end B; task body A is begin loop select accept Ask (Message : in out Unbounded_String) do Message := To_Unbounded_String ("Hi back"); end Ask; or terminate; end select; end loop; end A; task body B is Message : Unbounded_String; begin Message := To_Unbounded_String ("Hi"); Put_Line ("Send " & To_String (Message)); A.Ask (Message); Put_Line ("Received " & To_String (Message)); end B; begin null; end Talk; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de