comp.lang.ada
 help / color / mirror / Atom feed
* Confused About Task Priorities (Ada 83)
@ 1998-02-25  0:00 Charles H. Sampson
  1998-02-26  0:00 ` Robert Dewar
  0 siblings, 1 reply; 2+ messages in thread
From: Charles H. Sampson @ 1998-02-25  0:00 UTC (permalink / raw)



     I'm very confused in an area of Ada 83 that I thought I knew pret-
ty well: Task priorities.  I'm working on an old, poorly-documented 
program that is compiled with an obsolete compiler.  The project has 
dropped its compiler maintenance contract because there's nobody left at 
the company who can answer questions about it anymore.  There are indi-
cations in the source code that preemptive task scheduling is not the 
default.  These indications are non-standard calls to the real-time ex-
ecutive that explicitly turn preemption on.  (I'm talking true preemp-
tion here, tasks of different priorities, not time-slicing.)

     I wrote a little program to see if preemption is the default or 
not.  I have three compilers available and I'm getting my expected re-
sults for only one of them.

     Here's the program, with a lot of what I think is extraneous mate-
rial cut out.  That material can be supplied if anyone thinks it's 
needed.

WITH Calendar; USE Calendar;
PROCEDURE New_test IS

-- Declarations for storing the time information are here 

   PROCEDURE Busy_wait (Length : IN Duration) IS ...
-- Busy_wait loops until it chews up approximately the number of
-- CPU seconds given by Length 

   TASK Low IS
      ENTRY Start;
      ENTRY Finish;
      PRAGMA Priority (6);
   END Low;

   TASK Medium IS
      ENTRY Start;
      ENTRY Finish;
      PRAGMA Priority (7);
   END Medium;

   TASK High IS
      ENTRY Start;
      ENTRY Finish;
      PRAGMA Priority (8);
   END High;

   TASK BODY Low IS

   BEGIN
      ACCEPT Start DO
         Low_start := Clock;
      END Start;
      Low_start_busy := Clock;
      Busy_wait (4.0);
      Low_end_busy := Clock;
      ACCEPT Finish;
   END Low;

   TASK BODY Medium IS

   BEGIN
      ACCEPT Start DO
         Medium_start := Clock;
      END Start;
      Medium_start_low := Clock;
      Low.Start;
      Medium_start_busy_1 := Clock;
      Busy_wait (5.0);
      Medium_start_high := Clock;
      High.Start;
      Medium_start_busy_2 := Clock;
      Busy_wait (6.0);
      Medium_end_busy_2 := Clock;
      ACCEPT Finish;
   END Medium;

   TASK BODY High IS

   BEGIN
      ACCEPT Start DO
         High_start := Clock;
      END Start;
      High_start_busy := Clock;
      Busy_wait (7.0);
      High_end_busy := Clock;
      ACCEPT Finish;
   END High;

BEGIN
  Medium.Start;
  Low.Finish;
  Medium.Finish;
  High.Finish;
-- Code to print out the time snapshots appears here
END New_test;

     Here's the behavior I expect:

     Medium starts and snapshots its starting time.
     Medium snapshots the time and starts Low.
     Low starts and snapshots its starting time while the rendezvous 
executes at priority 7.
     After the rendezvous, Low and Medium are ready to run, so Medium 
snapshots the time and begins executing its first busy wait.
     After Medium executes its busy wait it snapshots the time and 
starts High.
     High starts and snapshots its starting time while the rendezvous 
executes at priority 8.
     After the rendezvous, Low, Medium, and High are ready to run, so 
High snapshots the time and starts its busy wait.
     After High finishes its busy wait it snapshots the time and sus-
pends at its accept statement for Finish.
     Medium and Low are now ready to run, so Medium snapshots the time, 
executes its second busy wait, snapshots the time, and suspends at its 
accept statement for Finish.
     Now Low is the only task ready to run, so it snapshots the time, 
executes its busy wait, and suspends at its accept statement for Finish.

    Am I right or wrong?  For the two compilers that don't show the 
expected behavior, the indications are that Low and Medium are timeslic-
ing while Medium is executing its first busy wait.  (Low finishes its
busy wait before Medium finishes its.)  When we get to the point of Med-
ium starting High, Low is already finished and High takes priority over
Medium, as I expect.

				Charlie
--
******

    If my user name appears as "csampson", remove the 'c' to get my
correct e-mail address.




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

* Re: Confused About Task Priorities (Ada 83)
  1998-02-25  0:00 Confused About Task Priorities (Ada 83) Charles H. Sampson
@ 1998-02-26  0:00 ` Robert Dewar
  0 siblings, 0 replies; 2+ messages in thread
From: Robert Dewar @ 1998-02-26  0:00 UTC (permalink / raw)



Charles asks about the effect of priorites in Ada 83. You really cannot
say anything very definite about the semantics of a tasking program in
Ada 83. Priorities are only used to indicate urgency of a task, and it
is perfectly valid for example to time slice between different tasks
on the grounds that e.g. you are simulating a multi-processor.

I would say that the behavior you are seeing is odd, but not non-conforming
in Ada 93. If you want predictable scheduling behavior, use an Ada 95
compiler that implements Annex D.





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

end of thread, other threads:[~1998-02-26  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-02-25  0:00 Confused About Task Priorities (Ada 83) Charles H. Sampson
1998-02-26  0:00 ` Robert Dewar

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