comp.lang.ada
 help / color / mirror / Atom feed
From: Nige <nigel.scott@uk.thalesgroup.com>
Subject: Re: multitasking: finishing execution
Date: Thu, 20 Jun 2002 13:48:39 +0100
Date: 2002-06-20T12:47:55+00:00	[thread overview]
Message-ID: <3D11CF27.90401@uk.thalesgroup.com> (raw)
In-Reply-To: 1HhQ8.8744$ZP1.1591823@news11-gui.server.ntli.net

chris.danx wrote:
> Hi,
> 
> Is calling the entry finish sufficient to terminate the task?  The code of
> the entry isn't the concern, but the behaviour of entries.  Consider the
> following procedure
> 
> procedure finish_tasks is
> begin
>    some_task.finish;                                     -- 1
>    ada.text_io.put ("some_task should have terminated"); -- 2
> end finish_tasks;
> 
> 
> -- sample task code
> --
> loop
>    select
>       accept Finish;
>       exit;
>    else
>       -- do some processing (sample code)
>       --
>       if x < integer'last then
>          x := x + 1;
>       end if;
>    end select;
> end loop;
> 
> 
> Can the call to some_task.finish time out?  If it can there's no guarantee
> that the task has finished executing before the call to ada.text_io.put is
> executed and the program may fail to terminate because it has running tasks,
> correct?
> 
> As you can see I'm a little confused by the fact that an entry can time out.
> Does it mean that the call can time out no matter what or that the task has
> to contain the appropriate code for an entry call to time out (such as a
> delay altenative)?  i.e. will the procedure wait indefinitely for the task
> to terminate or will it abandon the entry call after some time elapses?
> 
> If the code doesn't work as intended, what solution would you recommend?  Is
> there a better way?

select
    accept Finish;
else
    -- do code
    ....
end select;

will only process the accept if there is an outstanding call to it. For 
a call to timeout, you need to use:

select
    some_task.finish;
or
    delay <time>;
end select;

which will wait for up to <time> seconds for the call to be accepted, 
before giving up.

Also, in the following, it will wait for <time> seconds before executing 
the code after it, unless Finish is called into the meantime...

select
    accept Finish;
or
    delay <time>;
    -- do code
    ....
end select;


Hope that makes sense...

Nige





  reply	other threads:[~2002-06-20 12:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-20  9:57 multitasking: finishing execution chris.danx
2002-06-20 12:48 ` Nige [this message]
2002-06-20 16:19   ` chris.danx
2002-06-20 20:40     ` Stephen Leake
2002-06-20 14:53 ` Stephen Leake
2002-06-20 19:30   ` chris.danx
2002-06-21 18:14     ` Ted Dennison
replies disabled

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