comp.lang.ada
 help / color / mirror / Atom feed
* scheduler program in Ada
@ 1998-06-05  0:00 Rolf Ebert
  0 siblings, 0 replies; 3+ messages in thread
From: Rolf Ebert @ 1998-06-05  0:00 UTC (permalink / raw)



I'd like to write a scheduler in Ada much like the Unix crond
program.

The program has a cycle time of 5 minutes, for example.   A config file
specifies jobs which have to be started at a given offset from the 
start of the cycle.  That is I have a list of (offset,job) pairs.
The possible offsets have a resolution of 1/10 sec.  Theoretically
we could start 5*60*10=3000 jobs per 5min. cycle.

What is the best approach to do that in Ada?

I have thought about two possible solutions:
1) One task starts a new task every 1/10 sec. The newly created task
   looks into the (offset,jobs) - list and decides if anything is to do.
   If it is , it starts the corresponding job.  Either the task terminates
   after finishing the job or it stops if there is nothing to do.

2) As the list of (offset,job)-pairs does not change over time, the 
   scheduler can calculate the starting times once for all.  It can than 
   avoid starting unneccessary tasks .

Not having too much experience with the tasking facilities of Ada, is there
anything else I can do?

	Rolf
	ebert@wapor.muc.de
	ebert@muc.de
	ebert@pe-muc.de






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

* re: scheduler program in Ada
@ 1998-06-06  0:00 tmoran
  1998-06-06  0:00 ` Samuel Tardieu
  0 siblings, 1 reply; 3+ messages in thread
From: tmoran @ 1998-06-06  0:00 UTC (permalink / raw)



>Not having too much experience with the tasking facilities of Ada, is there
>anything else I can do?
Assuming the offsets in the file are in increasing order, it sounds
sort of like a merge between wall clock ticks and the to-do file.
Will something along these lines do what you want?
  start_time : ada.calendar.time := ada.calendar.clock;
  now: duration := 0;  -- duration since start_time
begin
  open the todo file containing records with (offset, job)
  loop
    read next todo record
    if todo.offset > now then
      delay todo.offset-now;
      now := ada.calendar.clock - start_time;
    end if;
    start todo.job
  end loop;




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

* Re: scheduler program in Ada
  1998-06-06  0:00 tmoran
@ 1998-06-06  0:00 ` Samuel Tardieu
  0 siblings, 0 replies; 3+ messages in thread
From: Samuel Tardieu @ 1998-06-06  0:00 UTC (permalink / raw)



>>>>> "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




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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-06-05  0:00 scheduler program in Ada Rolf Ebert
  -- strict thread matches above, loose matches on Subject: below --
1998-06-06  0:00 tmoran
1998-06-06  0:00 ` Samuel Tardieu

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