comp.lang.ada
 help / color / mirror / Atom feed
From: Anh Vo <anhvofrcaus@gmail.com>
Subject: Re: task model
Date: Thu, 15 Oct 2009 12:15:56 -0700 (PDT)
Date: 2009-10-15T12:15:56-07:00	[thread overview]
Message-ID: <6b6bd661-06b0-4ef6-8d48-0ef97d55fdd4@f20g2000prn.googlegroups.com> (raw)
In-Reply-To: c086cde9-96bf-47be-b56f-3793255788f2@a21g2000yqc.googlegroups.com

On Oct 15, 11:00 am, Ludovic Brenta <ludo...@ludovic-brenta.org>
wrote:
> Michael Tabak wrote on comp.lang.ada:
>
> > I'm prototyping some tasking with multiple accepts, the code is as
> > follows:
>
> > with Ada.Text_Io;
> > use Ada.Text_Io;
>
> > procedure task_test is
>
> >    procedure Process_Primary(node: in Integer) is
>
> >    begin
>
> >        Put_Line("This is number" & Integer'Image(node));
>
> >    end Process_Primary;
>
> >    task proc1 is
> >      entry process1(node : Integer);
> >      entry continue;
> >    end proc1;
>
> >    task body proc1 is
> >    begin
>
> >      accept process1( node : Integer) do
>
> >        Process_Primary( node );
>
> >      end;
>
> >      accept continue do
> >        Put_Line("Called Continue task1");
> >      end;
>
> >    end proc1;
>
> >    task proc2 is
> >      entry process2(node : Integer);
> >      entry continue;
> >    end proc2;
>
> >    task body proc2 is
> >    begin
>
> >      accept process2( node : Integer) do
>
> >          Process_Primary( node );
>
> >      end;
>
> >      accept continue do
> >        Put_Line("Called Continue task2");
> >      end;
>
> >    end proc2;
>
> > begin
> >   for i in 1..2 loop
> >    proc1.process1(1);
> >    proc2.process2(2);
> >    proc1.continue;
> >    proc2.continue;
> >   end loop;
> > end task_test;
> > ---------------------------------------------------------------------------­------------------------------------------
>
> > I get the out put I expect:
>
> > This is number 1
> > This is number 2
> > Called Continue task1
> > Called Continue task2
>
> > But I also get the following error which I can't track down:
>
> > raised TASKING_ERROR : s-tasren.adb:486
>
> Your expectations are wrong :)
>
> Your environment task contains a loop calling each task four times:
> for each task the call sequence is processN, continue, processN,
> continue.  But the tasks do not contain a loop, so they can accept
> only the first two entry calls and then they terminate.  So the second
> call to process1 raises Tasking_Error because task1 has terminated by
> now.

I would like to expand Ludovic's comment.

You have a couple of options to improve it.

1. Make sure the task not terminated before calling its entry. That is
using proc1'terminated syntax to query it.
2. Add infinite loop enclosing accept statements. So, entry call can
be served always. This makes tasks alive even after the program ends
(program will hang) unless Ctrl-C or other mean to end it. The clean
solution is add entry Shutdown to the task. When this entry is
invoked, just exit the loop. Thus, the task will terminate cleanly.

Anh Vo





  reply	other threads:[~2009-10-15 19:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-15 17:43 task model Mike
2009-10-15 18:00 ` Ludovic Brenta
2009-10-15 19:15   ` Anh Vo [this message]
2009-10-15 19:54     ` Dmitry A. Kazakov
2009-10-15 20:15       ` Jeffrey R. Carter
2009-10-16 14:06       ` Georg Bauhaus
2009-10-16 14:57         ` Brad Moore
2009-10-16 20:06         ` Jeffrey R. Carter
2009-10-17 11:10           ` Georg Bauhaus
2009-10-17 12:18             ` Dmitry A. Kazakov
2009-10-17 17:34             ` Jeffrey R. Carter
2009-10-19  7:56         ` Jean-Pierre Rosen
2009-10-15 19:55     ` sjw
replies disabled

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