Midterm #2 Study Question Answers
- If an operating system implements preemption of an executing process, it can still use a non-preemptive scheduling policy. Explain the difference between low level preemption and preemptive scheduling policy.
Preemption at a low level is a facility for suspending the execution of a process or thread (generally due to a clock interupt) and switching to a kernel context to enter the operating system and enable it to perform necessary work.
That work can include a number of different functions, including monitoring the exeucting process, performing asyncrhonous I/O operatins, and applying scheduling policy.
If the OS implements a preemptive scheduling policy, it might decide not to return to the suspended user process but to execute a different one instead.
However, if the OS implements a non-preemptive scheduling policy, then it will always resume the suspended user process unless it has relinquished the CPU.
- Explain why the straightforward implementation of the Critical Section problem (Figure 6.7 in Section 6.4 of Silberschatz Ed. 8) does not guarantee non-starvation.
Upon relinquishing the lock in the by setting it to false, a process may
immediately reenter the entry section, contending for the lock again
and obtaining it.
There is no guarantee that any other contending process will be allowed to run
before that process obtains the lock again.
Thus, one process can monopolize the lock and the others may starve.
- Define the reader/writer problem and explain how it can be solved using only mutexes.
Consider a shared resource which has two operations defined on it: read and write. If any process may be writing to the resource, no other process can be allowed to read or write it. However, any number of read-only processes may access the object concurrently.
A solution to the program that uses two mutexes is as follows:
- One mutex is the write lock called wrt. Any writer must obtain the write lock before accessing the resource, and release it when it is done.
- The other mutex called mutex is used to protect a shared variable readers that counts the number of readers that current have access to the resource.
- When a reader wants to access the resource it must obtain mutex and then it can increment the readers count. If the readers count is now one, then it is the first reader, and so must obtain the write lock before releasing mutex and then accessing the resource.
- When a reader is done accessing the resource it must obtain mutex and decrement readers. If the reader count is now zero, then it must release the write lock and then release mutex.
Write pseudocode for a solution to the Bounded Buffer problem that using semaphores.
See Section 6.6.1 in Silberschatz Ed. 8.