The and operations on counting semaphores, where s is a counting semaphore, are defined as follows:
|
|
|
|
|
Assume that and the wait and signal operations on binary semaphores are provided. Two binary semaphores and are used to implement the semaphore operations and as follows:
|
|
|
The initial values of and are respectively
View worked solution
Answer: C
To determine the initial values of the binary semaphores and , let us analyze their roles in the implementation of the counting semaphore operations:
-
Role of :
The variable is a shared integer representing the semaphore count. In both and , the operations on (such as decrementing, incrementing, and checking its value) must be executed atomically to prevent race conditions.
The binary semaphore is used to provide mutual exclusion (acting as a mutex) around these critical sections. Since a process must be allowed to enter the critical section initially, the mutex must be initialized to .
-
Role of :
The binary semaphore is used to block processes when the resource count is less than .
When a process calls and finds , it releases the mutex and then executes to block itself. For the process to successfully block at , the semaphore must be unavailable initially. Thus, must be initialized to .
When another process calls and increments such that , it signals to wake up one of the blocked processes.
Therefore, the initial values of and are and respectively.
Free practice · Your answers on this page are not saved.
