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: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "G.B." Newsgroups: comp.lang.ada Subject: cobegin ... coend Date: Sat, 1 Jul 2017 09:11:57 +0200 Organization: A noiseless patient Spider Message-ID: Reply-To: nonlegitur@notmyhomepage.de Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 1 Jul 2017 07:08:12 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="c889af1d1104442b0c96bfc4df2f1908"; logging-data="4904"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19BU2xfz8mpsvH7dHu1dusnmVrMpE8/kJg=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 X-Mozilla-News-Host: news://news.arcor.de:119 Cancel-Lock: sha1:5+L2p4MJAPkQHA+tHaMc94l+ZC8= Xref: news.eternal-september.org comp.lang.ada:47245 Date: 2017-07-01T09:11:57+02:00 List-Id: A chapter about concurrent processes an older book introduces the notation *cobegin* S1; S2; ...; Sn *coend*. It is also presenting a procedure as an example. An attempt at translating it into Ada is given below. Ignoring the premiss that Ada processes are tasks and that designing algorithms should therefore not ignore tasks, is there a known good way of translating the start of processes from *cobegin*...*coend* style to tasks? Or from OpenMP to tasks, I should think. (Paraffin only?) The example procedure Copy copies a sequence of records to another sequence, emptying the source. Package Sequences is an instance of Ada.Containers.Doubly_Linked_Lists. procedure Get (Item : out Copyable; Sequence : in out Sequences.List); procedure Put (Item : in Copyable; Sequence : in out Sequences.List); procedure Copy (F, G : in out Sequences.List) is S, T : Copyable; Completed : Boolean; begin if not F.Is_Empty then Completed := False; Get (S, F); loop T := S; -- cobegin Put (T, G); if F.Is_Empty then Completed := True; else Get (S, F); end if; -- coend exit when Completed; end loop; end if; end Copy; The "processes" in the marked section, i.e. Put and if-statement use disjoint sets of variables. My first translation has picked the easier part, by having a local task perform Put (T, G). procedure Copy_1 (F, G : in out Sequences.List) is S, T : Copyable; Completed : Boolean; task Assistant is entry Put; end Assistant; task body Assistant is begin loop select accept Put; Put (T, G); or terminate; end select; end loop; end Assistant; begin if not F.Is_Empty then Completed := False; Get (S, F); loop T := S; -- cobegin Assistant.Put; if F.Is_Empty then Completed := True; else Get (S, F); end if; -- coend exit when Completed; end loop; end if; end Copy_1; The second "process" between *cobegin* and *coend* seemed trickier, as the surrounding control structure depends on the process's result, i.e., on variable Completed having been set in time. So, the loop needs to wait for another rendezvous, for example. Are such things planned for Ada 2X's new parallel features?