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: buffer2.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: Simp,e example for 2 tasks Date: Sun, 21 Sep 2014 13:33:29 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <9b22dd09-6137-4f4b-8be1-28255032df70@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Sun, 21 Sep 2014 20:33:33 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="ff2e5d21b9fb0a12a9871c15f1d89f02"; logging-data="19030"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lexu7a51l7FnDrYIm1azjxsFnCGEh2ao=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.0 In-Reply-To: Cancel-Lock: sha1:drU1/0h9x1j3PyAo3TBqwjYEcv4= Xref: number.nntp.dca.giganews.com comp.lang.ada:189075 Date: 2014-09-21T13:33:29-07: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". As others have pointed out, Ada tasking is based on synchronous communication, not the message queues found in other languages. This why Ada had to introduce the partition concept to achieve distribution, while Erlang processes distribute quite nicely by themselves, as the ping-pong example shows. It follows that to have message passing in Ada one must create the mechanism that stores a message from one task and allows another task to retrieve it. In Ada 12 one can use the synchronized-queue containers for that. with Ada.Containers.Synchronized_Queue_Interfaces; with Ada.Containers.Bounded_Synchronized_Queues; with Ada.Strings.Unbounded; procedure Task_Example is package String_Queue_IF is new Ada.Containers.Synchronized_Queue_Interfaces (Element_Type => Ada.Strings.Unbounded.Unbounded_String); package String_Queues is new Ada.Containers.Bounded_Synchronized_Queues (Queue_Interfaces => String_Queue_IF, Default_Capacity => 1); A_To_B : String_Queues.Queue; B_To_A : String_Queues.Queue; task A; task B; task body A is Message : Ada.Strings.Unbounded.Unbounded_String; begin -- A A_To_B.Enqueue (New_Item => Ada.Strings.Unbounded.To_String ("Hi") ); B_To_A.Dequeue (Element => Message); end A; task body B is Message : Ada.Strings.Unbounded.Unbounded_String; begin -- B A_To_B.Dequeue (Element => Message); B_To_A.Enqueue (New_Item => Ada.Strings.Unbounded.To_String ("Hi back") ); end B; begin -- Task_Example null; end Task_Example; -- Jeff Carter "How'd you like to hide the egg and gurgitate a few saucers of mocha java?" Never Give a Sucker an Even Break 101