comp.lang.ada
 help / color / mirror / Atom feed
From: Samuel Tardieu <sam@ada.eu.org>
Subject: Re: scheduler program in Ada
Date: 1998/06/06
Date: 1998-06-06T00:00:00+00:00	[thread overview]
Message-ID: <m3d8cmzmlh.fsf@zaphod.enst.fr> (raw)
In-Reply-To: 6la99o$jcu@lotho.delphi.com


>>>>> "T" == tmoran  <tmoran@bix.com> writes:

T> Will something along these lines do what you want?
T>   start_time : ada.calendar.time := ada.calendar.clock;
T>   now: duration := 0; -- duration since start_time
T> begin
T>   open the todo file containing records with (offset, job)
T>   loop
T>     read next todo record
T>     if todo.offset > now then
T>       delay todo.offset-now;
T>       now := ada.calendar.clock - start_time;
T>     end if;
T>     start todo.job
T>   end loop;

This is a typical situation where "delay until" is much more useful
than "delay" for two reasons:

  1) You compute "now", then do a test, then sleep for "todo.offset -
     now". This means that "now" is no longer accurate (if your system 
     is damn slow) at the time of substraction.

  2) If you have other tasks and get preempted just before the delay,
     you will sleep for too long a time.

The following scheme should be better:

  loop
    read next todo record
    delay until todo.offset + start_time
    start todo.job
  end loop

It also makes the test unnecessary, since if "todo.offset + start_time" 
is before the current time, the "delay until" will have no effect.

  Sam
-- 
Samuel Tardieu -- sam@ada.eu.org




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

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-06-06  0:00 scheduler program in Ada tmoran
1998-06-06  0:00 ` Samuel Tardieu [this message]
  -- strict thread matches above, loose matches on Subject: below --
1998-06-05  0:00 Rolf Ebert
replies disabled

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