These
programs are to be run on plain DOS (not in a Windows DOS box).
Exercises the monitor API. The main task acts
as a producer, reading keys from the keyboard and sending them one at a time to
a consumer task via a shared variable. End the program by hitting ‘Q’.
Exercises the pipe API. The main task acts as a
producer, reading lines from the keyboard and sending them to a consumer task
through a pipe. End the program by entering an empty line.
Exercises the message queue API. The main task acts as a producer, reading lines from the keyboard and
interpreting them as integer values. It sends them them to a consumer task
through a message queue, the size of the messages being the size of an integer.
End the program by entering an empty line.
Exercises the kernel’s messaging API. The main
task acts as a producer, reading lines from the keyboard and sending them to a
consumer task. End the program by entering an empty line.
Shows the effect of protecting or not
protecting the 80387 from preemptions. This program has two tasks: there is a
lower priority task that runs continuously making some arithmetic calculations.
This task runs silently, and only prints error messages when it discovers that
two floating point variables which are suposedly equal are actually different.
The main task has higher priority and is blocked at the keyboard. When it gets
a key, it does the same calculation as the background task. The program takes
three boolean (0/1) arguments:
pmath protect_main protect_background
use_coprocessor
The following combination produces errors in
the background task:
pmath
1 0 1
This happens because the background task is
preempted by the higher-priority main task when the user hits a key, and its
coprocessor status is trashed. End the program by hitting ‘Q’.
This program exercises setting different timer
tick durations, timer callbacks and using DelayUntil() vs. Delay()
in periodic tasks. It works as follows: three periodic tasks are created with a
lower priority than the main task. Each of them increments a counter in each
cycle and either Delay() for their assigned number of milliseconds, or DelayUntil()
the next deadline. A timer callback is also installed, which counts timer ticks
only when the main task is sleeping. After starting the tasks, the main task
sleeps for 1 second, prints the counters and ends the program. Due to their
lower priority, the periodic tasks will only run when the main task is blocked;
this guarantees that they will run for exactly 1 second. The callback counts
the number of timer ticks falling withing the same 1-second interval. Upon
program termination, all counters and their theoretically expected values are
printed.
The program accepts up to 5 optional arguments:
ptime tick
delay_until t1 t2
t3
tick
= duration of the timer tick in milliseconds (1-55) – default = 1
delay_until
= use DelayUntil() (boolean) - default = 0
t1,
t2, t3 = task periods in milliseconds – defaults = 1, 10, 100
For fast periodic tasks (when their period is a
small number of ticks) the DelayUntil() method proves to be more
accurate.
This is an implementation of an algorithm to
control a one-lane piece of road. Cars may enter the one-lane section from the
left or from the right. Each car is a separate task. There is a controlling
task, which receives messages from the cars when they pass certain road-side
sensors and controls opening and closing of the barriers at each end of the
one-lane section. The sensors are located near the barriers and at the
barriers, they appear as stars on the screen. An optional argument specifies
how many cars are allowed to pass in one direction before the sense is
reversed, in order to avoid starvation; default is 10. Send a car to the left
by hitting ‘L’, send a car to the right by hitting ‘R’, quit by hitting ‘Q’.
An implementation of the classical dining
philosophers problem, solved by using a monitor. See A. Tanenbaum, Operating
Systems Design and Implementation. The status of a philosopher is shown as
either “THINKING”, “HUNGRY” or “EATING”. Fork status is shown as “used” or
“free”. End the program by hitting any key.