Synchronization Tools: Practice Exercises
Synchronization Tools: Practice Exercises
6
CHAPTER
Tools
Practice Exercises
6.1 In Section 6.4, we mentioned that disabling interrupts frequently can
affect the system’s clock. Explain why this can occur and how such
effects can be minimized.
Answer:
The system clock is updated at every clock interrupt. If interrupts were
disabled —particularly for a long period of time —the system clock
could easily lose the correct time. The system clock is also used for
scheduling purposes. For example, the time quantum for a process is
expressed as a number of clock ticks. At every clock interrupt, the sched-
uler determines if the time quantum for the currently running process
has expired. If clock interrupts were disabled, the scheduler could not
accurately assign time quanta. This effect can be minimized by disabling
clock interrupts for only very short periods.
6.2 What is the meaning of the term busy waiting? What other kinds of
waiting are there in an operating system? Can busy waiting be avoided
altogether? Explain your answer.
Answer:
Busy waiting means that a process is waiting for a condition to be satisfied
in a tight loop without relinquishing the processor. One strategy to avoid
busy waiting temporarily puts the waiting process to sleep and awakens
it when the appropriate program state is reached, but this solution incurs
the overhead associated with putting the process to sleep and later
waking it up.
6.3 Explain why spinlocks are not appropriate for single-processor systems
yet are often used in multiprocessor systems.
Answer:
Spinlocks are not appropriate for single-processor systems because the
condition that would break a process out of the spinlock can be obtained
only by executing a different process. If the process is not relinquishing
the processor, other processes do not get the opportunity to set the
269
270 Chapter 6 Synchronization Tools
do {
wait(mutex);
/* critical section */
signal(mutex);
/* remainder section */
} while (true);