Category : Miscellaneous Language Source Code
Archive   : EUPHOR10.ZIP
Filename : SCHED.E

 
Output of file : SCHED.E contained in archive : EUPHOR10.ZIP
-- sched.e
-- Task Scheduler

global constant HUGE_TIME = 1e30

constant sample_interval = 1.0
atom sample_count

type reasonable_delay(atom x)
return x > 0 and x < 30
end type

global procedure init_delay()
-- since time() may not have fine enough
-- resolution for small delays, we see how many for-loop iterations
-- we can complete over a small sample period

atom t

t = time() + sample_interval
for i = 1 to 999999999 do
if time() < t then
else
sample_count = i
exit
end if
end for
end procedure

global procedure delay(reasonable_delay t)
-- delay for t seconds
atom stop
if t > sample_interval then
-- time() should be precise enough
stop = time() + t
while time() < stop do
end while
else
-- loop a certain number of times
stop = time() + sample_interval
for i = 1 to floor(t / sample_interval * sample_count) do
if time() < stop then
else
end if
end for
end if
end procedure


global procedure sched(task t, positive_atom wait)
-- schedule task to be reactivated in wait seconds

if wait = 0 then
-- deactivate
tcb[t] = HUGE_TIME
else
-- activate in wait seconds from now
tcb[t] = time() + wait
end if
end procedure


global function next_task()
-- choose the next task to be executed

positive_atom mintime
task mintask

-- find task with minimum time
mintime = HUGE_TIME
for i = 1 to NTASKS do
if tcb[i] < mintime then
mintask = i
mintime = tcb[i]
end if
end for

-- subtract it's early-activation tolerance
tcb[mintask] = tcb[mintask] - eat[mintask]

-- wait until it is time to activate it
while time() < tcb[mintask] do
end while

return mintask
end function



  3 Responses to “Category : Miscellaneous Language Source Code
Archive   : EUPHOR10.ZIP
Filename : SCHED.E

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/