comp.lang.ada
 help / color / mirror / Atom feed
* Tasking and blocked threads
@ 1999-09-09  0:00 Andy Askey
  1999-09-10  0:00 ` Robert A Duff
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andy Askey @ 1999-09-09  0:00 UTC (permalink / raw)


This is really a Apex Ada95 specific question, but maybe someone on here
has experience in this area.

I wrote the following simple program to determine the difference between
the STANDARD Ada95 model and the THREADED Ada95 model with Apex 3.0.0b
on a Solaris 2.6 OS.  The output from the STANDARD model swaps between
tasks alternating grouped lines of output.  A bunch of "in task one"
lines are followed by a bunch of "YOMOMMA!!!!!" lines.  I was told that
this was due to time slicing in the STANDARD model. 

When I compiled with the THREADED model, I observed pretty much the same
thing.  Even though the bunches of lines of text looked a little
different with the THREADED model, it was obvious that the program was
switching between the main and task one threads.  My question: why are
both threads getting CPU time?  (I verified with "Show Imports" that I
was using the THREADED views (see text following the code.)

I added delay statements to see if one task would block the other, but
it did not.  I added a Task_Two package and execution control was passed
between all three threads. I thought I understood from previous answers
that this was not expect behavior.  Does this mean I can write an Ada95
program with several independent tasks and not worry about one task
blocking another?  (Stealing CPU cycles yes, but not really blocking.)

Thanx.
Andy

--
-- File Name: task_one.1.ada
-- 
package Task_One is
    task One;
end Task_One;
--
-- File Name: task_one.2.ada
--
with Ada.Text_Io;
package body Task_One is
    task body One is
    begin
        loop
            ada.text_io.Put_Line ("in task one");
        end loop;
    end One;
end Task_One;

--
-- File Name: mainproc.2.ada
--
with Task_One;
with Ada.Text_Io;
procedure Mainproc is
begin
    loop
        ada.text_io.Put_Line ("YOMOMMA!!!!!");
    end loop;
end Mainproc;


-------------

 testout.ss/threaded.wrk
 Explicit Imports
   lrm.ss         sun4_solaris2.ada95.thread.3.0.0.rel  all_units
   numerics.ss    sun4_solaris2.ada95.thread.3.0.0.rel  all_units
   posix.ss       sun4_solaris2.ada95.thread.3.0.0.rel  all_units
   predefined.ss  sun4_solaris2.ada95.thread.3.0.0.rel  all_units
   rational.ss    sun4_solaris2.ada95.thread.3.0.0.rel  all_units
   systems_programming.ss  sun4_solaris2.ada95.thread.3.0.0.rel 
all_units
-- 
---------------------------------------------------
|                 Andy Askey                      |
|              Software Engineer                  |
|           Raytheon Systems Company              |
|   670 Discovery Drive, Huntsville, AL  35806    |
|   Phone: (256) 971-2367  Fax: (256) 971-2306    |
|        andrew_j_askey@res.raytheon.com          |
---------------------------------------------------




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Tasking and blocked threads
  1999-09-09  0:00 Tasking and blocked threads Andy Askey
  1999-09-10  0:00 ` Robert A Duff
@ 1999-09-10  0:00 ` Ted Dennison
  1999-09-11  0:00 ` Martin Dowie
  2 siblings, 0 replies; 4+ messages in thread
From: Ted Dennison @ 1999-09-10  0:00 UTC (permalink / raw)


In article <37D849AE.AC5EA4F1@res.raytheon.com>,
  Andy Askey <askeya@res.raytheon.com> wrote:

> I added delay statements to see if one task would block the other, but
> it did not.  I added a Task_Two package and execution control was
passed
> between all three threads. I thought I understood from previous
answers
> that this was not expect behavior.  Does this mean I can write an
Ada95
> program with several independent tasks and not worry about one task
> blocking another?  (Stealing CPU cycles yes, but not really blocking.)

That depends entirely on your tasking model. The only one defined by the
language is FIFO_Within_Priorities (and that only if your compiler
supports annex D).


--
T.E.D.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Tasking and blocked threads
  1999-09-09  0:00 Tasking and blocked threads Andy Askey
@ 1999-09-10  0:00 ` Robert A Duff
  1999-09-10  0:00 ` Ted Dennison
  1999-09-11  0:00 ` Martin Dowie
  2 siblings, 0 replies; 4+ messages in thread
From: Robert A Duff @ 1999-09-10  0:00 UTC (permalink / raw)


Andy Askey <askeya@res.raytheon.com> writes:

> the STANDARD Ada95 model and the THREADED Ada95 model with Apex 3.0.0b
> on a Solaris 2.6 OS.  The output from the STANDARD model swaps between
> tasks alternating grouped lines of output.  A bunch of "in task one"
> lines are followed by a bunch of "YOMOMMA!!!!!" lines.  I was told that
> this was due to time slicing in the STANDARD model. 

Formally, the execution of this program is erroneous, and therefore
completely unpredictable, because two tasks are simultaneously writing
upon the same variable (the current output file).  So the compiler can
do whatever it likes.

Probably what's actually going on is that the I/O causes the tasks to
block.  That's allowed (and usually desirable).  Replace the I/O with
some in-memory manipulations of data structures, and see if the behavior
changes.

Of course, an implementation can provide whatever task dispatching
policies it likes; the run-till-blocked semantics is part of the Real
Time Annex.

- Bob
-- 
Change robert to bob to get my real email address.  Sorry.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Tasking and blocked threads
  1999-09-09  0:00 Tasking and blocked threads Andy Askey
  1999-09-10  0:00 ` Robert A Duff
  1999-09-10  0:00 ` Ted Dennison
@ 1999-09-11  0:00 ` Martin Dowie
  2 siblings, 0 replies; 4+ messages in thread
From: Martin Dowie @ 1999-09-11  0:00 UTC (permalink / raw)


in apex, you can use 'pragma Main' to switch between blocking and
non-blocking text_io - might be interesting to see if there was any
difference in behaviour after that...

Andy Askey wrote:

> This is really a Apex Ada95 specific question, but maybe someone on here
> has experience in this area.
>
> I wrote the following simple program to determine the difference between
> the STANDARD Ada95 model and the THREADED Ada95 model with Apex 3.0.0b
> on a Solaris 2.6 OS.  The output from the STANDARD model swaps between
> tasks alternating grouped lines of output.  A bunch of "in task one"
> lines are followed by a bunch of "YOMOMMA!!!!!" lines.  I was told that
> this was due to time slicing in the STANDARD model.
>
> When I compiled with the THREADED model, I observed pretty much the same
> thing.  Even though the bunches of lines of text looked a little
> different with the THREADED model, it was obvious that the program was
> switching between the main and task one threads.  My question: why are
> both threads getting CPU time?  (I verified with "Show Imports" that I
> was using the THREADED views (see text following the code.)
>
> I added delay statements to see if one task would block the other, but
> it did not.  I added a Task_Two package and execution control was passed
> between all three threads. I thought I understood from previous answers
> that this was not expect behavior.  Does this mean I can write an Ada95
> program with several independent tasks and not worry about one task
> blocking another?  (Stealing CPU cycles yes, but not really blocking.)
>
> Thanx.
> Andy
>
> --
> -- File Name: task_one.1.ada
> --
> package Task_One is
>     task One;
> end Task_One;
> --
> -- File Name: task_one.2.ada
> --
> with Ada.Text_Io;
> package body Task_One is
>     task body One is
>     begin
>         loop
>             ada.text_io.Put_Line ("in task one");
>         end loop;
>     end One;
> end Task_One;
>
> --
> -- File Name: mainproc.2.ada
> --
> with Task_One;
> with Ada.Text_Io;
> procedure Mainproc is
> begin
>     loop
>         ada.text_io.Put_Line ("YOMOMMA!!!!!");
>     end loop;
> end Mainproc;
>
> -------------
>
>  testout.ss/threaded.wrk
>  Explicit Imports
>    lrm.ss         sun4_solaris2.ada95.thread.3.0.0.rel  all_units
>    numerics.ss    sun4_solaris2.ada95.thread.3.0.0.rel  all_units
>    posix.ss       sun4_solaris2.ada95.thread.3.0.0.rel  all_units
>    predefined.ss  sun4_solaris2.ada95.thread.3.0.0.rel  all_units
>    rational.ss    sun4_solaris2.ada95.thread.3.0.0.rel  all_units
>    systems_programming.ss  sun4_solaris2.ada95.thread.3.0.0.rel
> all_units
> --
> ---------------------------------------------------
> |                 Andy Askey                      |
> |              Software Engineer                  |
> |           Raytheon Systems Company              |
> |   670 Discovery Drive, Huntsville, AL  35806    |
> |   Phone: (256) 971-2367  Fax: (256) 971-2306    |
> |        andrew_j_askey@res.raytheon.com          |
> ---------------------------------------------------





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1999-09-11  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-09  0:00 Tasking and blocked threads Andy Askey
1999-09-10  0:00 ` Robert A Duff
1999-09-10  0:00 ` Ted Dennison
1999-09-11  0:00 ` Martin Dowie

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