comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Ada Thread Termination
Date: Mon, 04 Feb 2008 18:26:56 -0500
Date: 2008-02-04T18:26:56-05:00	[thread overview]
Message-ID: <wccejbs481r.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 48309f0b-8474-4973-aaba-50b5d63f0abd@m34g2000hsb.googlegroups.com

Adam Beneschan <adam@irvine.com> writes:

> Well, Dmitry's suggestion might work in this particular case.

I've used something like Dmitry's suggestion in the past,
and it worked fine.

> However, in general, I'm not sure it's a good idea to put blocking
> calls like this in a task; they may not work.

In some implementations, it might block the entire program,
which is not what you want.  But I think in most implementations,
including GNAT, it will block the current task, which is fine.

> To take a simple example: Although you're referring to a multi-
> threaded program, it's possible to implement tasking with a single
> thread, possibly using a timer to interrupt the program at various
> intervals so the tasking library can perhaps check to see if a higher-
> priority task is ready to run.  (I believe this is possible, although
> it may be impossible to support Annex D this way.)

I don't see the need for the timer interrupt in such an implementation.
And I don't see the problems with respect to Annex D.
I do see a problem with blocking system calls, as you note below:

>...Anyway, suppose
> that, in this sort of implementation, one of your tasks does a Unix
> read() to get input from some external source.  While the read() is in
> progress, your program will stop.  The other tasks will not be
> running, even if they're able to run, because read() has blocked the
> program outside of the knowledge of the tasking library, and the
> tasking library will not know what to do.

So in such a system, non-blocking I/O, with interrupt on completion,
is needed.

> Having said all that, this *might* work:
>
>     select
>         Termination_Task.Terminated;
>         Terminated := True;
>     then abort
>         Listen_For_Message;
>     end select;

Aborting system calls is treading on thin ice.  The Ada RM doesn't
require it to work, and in many cases it does not work.
So your "might" above should perhaps be a "will probably not".  ;-)

> "select then abort" needs an entry call or a delay statement to tell
> it when to abort the abortable part, so you'll need to set up some
> sort of entry in a third task, something like this:
>
>     task body Termination_Task is
>     begin
>        accept Time_To_Terminate;
>        accept Terminated;
>     end;

A protected object might be simpler than a task, here.

- Bob



      reply	other threads:[~2008-02-04 23:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-02 19:41 Ada Thread Termination shaunpatterson
2008-02-02 19:55 ` Dmitry A. Kazakov
2008-02-02 21:23 ` gpriv
2008-02-04 17:57 ` Adam Beneschan
2008-02-04 23:26   ` Robert A Duff [this message]
replies disabled

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