comp.lang.ada
 help / color / mirror / Atom feed
* cobegin ... coend
@ 2017-07-01  7:11 G.B.
  2017-07-01 10:47 ` Lucretia
  2017-07-03  0:17 ` Randy Brukardt
  0 siblings, 2 replies; 3+ messages in thread
From: G.B. @ 2017-07-01  7:11 UTC (permalink / raw)


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?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: cobegin ... coend
  2017-07-01  7:11 cobegin ... coend G.B.
@ 2017-07-01 10:47 ` Lucretia
  2017-07-03  0:17 ` Randy Brukardt
  1 sibling, 0 replies; 3+ messages in thread
From: Lucretia @ 2017-07-01 10:47 UTC (permalink / raw)


On Saturday, 1 July 2017 08:12:01 UTC+1, G.B.  wrote:
> A chapter about concurrent processes an older book
> introduces the notation
>       *cobegin* S1; S2; ...; Sn *coend*.

Concurrent Pascal?

> 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?

Yes, parallel blocks and loops.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: cobegin ... coend
  2017-07-01  7:11 cobegin ... coend G.B.
  2017-07-01 10:47 ` Lucretia
@ 2017-07-03  0:17 ` Randy Brukardt
  1 sibling, 0 replies; 3+ messages in thread
From: Randy Brukardt @ 2017-07-03  0:17 UTC (permalink / raw)


"G.B." <bauhaus@notmyhomepage.invalid> wrote in message 
news:oj7hos$4p8$1@dont-email.me...
...
> 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?

Wait for the next version of Ada and use a parallel block or loop?? (See 
AI12-0119-1, please note that this seems to change drastically at each 
meeting so don't depend too much on the details).

                       Randy.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-07-03  0:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-01  7:11 cobegin ... coend G.B.
2017-07-01 10:47 ` Lucretia
2017-07-03  0:17 ` Randy Brukardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox