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: confusion about message passing between the tasks Date: Sat, 25 Oct 2014 08:58:23 +0100 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="71797db6fbf0039ebda7a9c799ddb33f"; logging-data="9250"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/YKUd5j25gTgf5ThXUuLwDSYIwkUd2tGA=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) Cancel-Lock: sha1:avh4zQi60/MpO61Zu3VycpkwlSg= sha1:o/pLHfPVCQKb8Ll2wIHmYAE0nJs= Xref: news.eternal-september.org comp.lang.ada:22720 Date: 2014-10-25T08:58:23+01:00 List-Id: compguy45@gmail.com writes: > I am really kind of lost with tasks and message passing. Would anyone > show me an example where 2 tasks would be created by environment > task...each task has same body and one entry...so for example one task > waits at entry while the other one completes the entry block and on > the exit lets waiting task that's its done. with Ada.Text_IO; use Ada.Text_IO; procedure Strib is type T; type T_Access is access T; task type T (Next : T_Access) is entry Start (Message : Integer); end T; task body T is Data : Integer; begin Put_Line ("waiting"); accept Start (Message : Integer) do Data := Message; end Start; Put_Line ("working with " & Integer'Image (Data)); delay 1.0; if Next /= null then Put_Line ("kicking off next task"); Next.Start (Data + 1); else Put_Line ("no next task"); end if; Put_Line ("done"); end T; Tasks : array (1 .. 2) of T_Access; begin -- we have to create the tasks in reverse order, because the first -- task needs to be able to reach the second task. Tasks (2) := new T (Next => null); Tasks (1) := new T (Next => Tasks (2)); Tasks (1).Start (42); end Strib;