Tips on Writing the Preemptive Minithreads System
Tips on Writing the Preemptive Minithreads System
Here are some basic tips (as usual, passed on through generations of
CSE 451 TAs) for writing the preemptive minithreads system.
- The clock ticks will not be called until you call
minithread_clock_init and install an interrupt service
routine. This routine will not be called until you enable interrupts
with enable_interrupts().
- Once enabled, the clock interrupt handler can be called at ANY
TIME (to change the clock period to something less than the 500
microseconds it is currently set to, change the #define in
clock.h).
- Consequently, you will need to ensure that everything you do
while scheduling threads, updating global structures etc. must be
protected in some way, either by disabling interrupts or by using
mutex's. However, note that enabling or disabling interrupts too many
times, is bad, so avoid doing so. Use some synchronization primitives
to protect kernel structures wherever possible.
- You may find it useful to implement spinlocks. Spinlocks are
really test-and-set locks where you continually test and set the lock
until you've acquired it. This means that the caller blocks until
they acquire the lock.
- Remember that semaphore_P and semaphore_V need
to run atomically.
- printf's will get messy (unless you put a semaphore
around them, but if you're trying to debug semaphores...). Remember
to fflush(stdout) after each printf, otherwise
things will get even more confusing because the printf's
won't necessarily print out stuff when you expect them to.
- Run your program a LOT of times, because each run will be
different, and new bugs may manifest themselves.
cse451-TA@cs.washington.edu