comp.lang.ada
 help / color / mirror / Atom feed
From: Anh Vo <anhvofrcaus@gmail.com>
Subject: Re: Q: Stopping a task running a long simulation
Date: Thu, 11 Mar 2010 10:11:06 -0800 (PST)
Date: 2010-03-11T10:11:06-08:00	[thread overview]
Message-ID: <9afd22da-66a9-4798-b2d1-c71269d35471@s36g2000prf.googlegroups.com> (raw)
In-Reply-To: f16d58ea-6ff2-44fd-85e1-fd482c2bf3e4@d27g2000yqf.googlegroups.com

On Mar 11, 5:08 am, Gautier write-only <gautier_niou...@hotmail.com>
wrote:
> Hello,
> Being still a bit new to tasking, I have a question of how to
> terminate correctly a certain kind of task.
> I have a task type which is waiting for running a potentially long
> simulation; it is kind of a "daemon".
> (the rationale of using a task type is that I have several simulations
> that can be run in parallel, hence an array of these tasks).
> Now this simulation occurs within a GUI, where the user might want to
> stop it.
> Here is the task type I've defined:
>
>   task type Simulation_type is
>     entry Start;
>     entry Run( [some parameters] );
>     entry Stop;
>   end;
>
>   Simulation: array(PF_version) of Simulation_type;
>
>   task body Simulation_type is
>   begin
>     accept Start;
>     loop
>       select
>         accept Stop;
>         exit;
>       or
>         accept Run( [some parameters] ) do
>           -- some quick parameter passing
>         end Run;
>         Compute( [some parameters] );
>       or
>         delay 0.2; -- relax
>       end select;
>     end loop;
>   end Simulation_type;
>
> For aborting the simulation, I have tried this (happens when the main
> GUI window is destroyed):
>     for v in PF_version loop
>       abort Daemons.Simulation(v);
>     end loop;
> but (as expected if I've understood Barnes' chapter correctly), the
> task waits for 'Compute' to complete.
> At least, it is what happens with GNAT under Windows: despite the
> above, the GUI closes but the program somehow is still alive and CPU-
> busy.
>
> I have an alternative to that.
> 'Compute' has a generic 'Feedback' procedure for showing progress.
> I could with that way give a Boolean, user_abort, to 'Feedback', and
> 'Compute' would stop when an ad-hoc exception is raised, and return
> normally on its own.
> Meanwhile, I could call the 'Stop' entry which could be soon be
> activated, since Compute would stop quickly, and the daemon task would
> be terminated, and I could close the shop properly.
>
> Now my question: is it the right way of doing it (I'm sure it will
> work), or is there something more straightforward ?
>

There is another alternative to shut them down. That is to replace
delay 0.2 statement by terminate alternative.

Calling Stop entry to shutdown the task is the gentle way to terminate
a task. How about to generate a signal to call Stop entry when the GUI
is closed.

Anh Vo



  reply	other threads:[~2010-03-11 18:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-11 13:08 Q: Stopping a task running a long simulation Gautier write-only
2010-03-11 18:11 ` Anh Vo [this message]
2010-03-12  0:24 ` tmoran
2010-03-12  1:15   ` Gautier write-only
2010-03-12  1:27 ` Adam Beneschan
2010-03-12  1:50   ` Gautier write-only
2010-03-12  2:03   ` Gautier write-only
replies disabled

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