comp.lang.ada
 help / color / mirror / Atom feed
From: Thomas Handler <th@umundum.vol.at>
Subject: Re: Tasking and preemption
Date: 1998/12/13
Date: 1998-12-13T00:00:00+00:00	[thread overview]
Message-ID: <3674433D.9932AFF@umundum.vol.at> (raw)
In-Reply-To: 74rr7n$4sp$1@nnrp1.dejanews.com

dennison@telepath.com wrote:
> 
> In article <36714AA1.96BD1AC5@systems.at>,
>   Thomas Handler <thandler@systems.at> wrote:
> > Hi to everyone!
> >
> > I'm trying to get into Ada and have now passed the tasking mechanism
> > provided by Ada95.
> > My problem is that my understanding of preempting seems not to match
> > with that of my system ;-)
> >
> > I'm using GNAT 3.09p on Linux with libpthreads and when doing a simple
> > program with two tasks where each task body is simply puttnig a string
> > in a loop to the screen the tasks seem to have a real cooperative
> > behavior, i.e. Task B starts working after Task A has finished
> > (independent of the length of the loop).
> > Building a delay into the loop has the desired effect.
> 
> Feel fortunate its working that way. Text_IO is typically not task-safe. You
> shouldn't be trying to write to the same file (the screen counts as a file)
> from two different concurrently-running tasks.
OK, it was not a quite good example using Text_IO but it was just for a
test ;-)

> 
> > So my question is: In the RM preemption is based on calling blocking
> > statements (like delay), as far as I understand there is no definition
> > of thread supported preemption. Is this true (i.e. I have to take care
> > in my program to make calls to blocking statements) or am I terribly
> > wrong?
> 
> There are multitudes of different scheduling policies that your system could
> be using. The only predfined one is FIFO_Within_Priorities (D.2.2). Under
> this policy a running task could concieveably hog the CPU forever unless it
> performs a rendezvous, accept, or a delay. Check out Annex D of the LRM. It
> has a very thourough treatment of this subject.
I have read this annex several times in LRM and AARM and with your above
answer it seems that I got itz the right way.
So this does actually mean that having a task that does heavy
computations has to be written 
a.) in a way that ensures that a blocking statement will be executed
from time to time
b.) this task runs on lower priority and the other tasks execute a
blocking statement (will this work ?)
c.) use a different (implementation dependant) scheduling policy (BTW:
which task dispatching policies are defined for GNAT?)

I have to admit that I have not used threads ever before on Unix due to
the fact that I have gained some experiences with them on a propietary
system developed by my former employer. After a look on the PThread
documentation I decided not to use them with C/C++ since the latter of
the combination itself is already troublesome :-)
But it seems strange to me since my understanding of threads always was
that they are preempting (that's why you a thread-safe library will help
a lot ;-) and GNAT uses libpthread. So I'm a bit surprised at the
moment.

Ciao,

Thomas Handler

> 
> --
> T.E.D.
> 
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own




  reply	other threads:[~1998-12-13  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-12-11  0:00 Tasking and preemption Thomas Handler
1998-12-11  0:00 ` dennison
1998-12-13  0:00   ` Thomas Handler [this message]
1998-12-14  0:00     ` Mats Weber
1998-12-14  0:00     ` dennison
1998-12-13  0:00   ` Thomas Handler
replies disabled

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