Consider a sharable resource with the following characteristics: (1) As long as there are fewer than three
Question:
Consider a sharable resource with the following characteristics:
(1) As long as there are fewer than three processes using the resource, new processes can start using it right away.
(2) Once there are three processes using the resource, all three must leave before any new processes can begin using it. We realize that counters are needed to keep track of how many processes are waiting and active, and that these counters are themselves shared resources that must be protected with mutual exclusion. So we might create the following solution:
The solution appears to do everything right: All accesses to the shared variables are protected by mutual exclusion, processes do not block themselves while in the mutual exclusion, new processes are prevented from using the resource if there are (or were) three active users, and the last process to depart unblocks up to three waiting processes.
a. The program is nevertheless incorrect. Explain why.
b. Suppose we change the if in line 6 to a while. Does this solve any problem in the program? Do any difficulties remain?
Step by Step Answer:
Operating Systems Internals and Design Principles
ISBN: 978-0133805918
8th edition
Authors: William Stallings