Solution
The correct answer is 18
Key Points
A counting semaphore is a synchronization mechanism used in concurrent programming to control access to a shared resource. It maintains a counter that can be incremented or decremented, allowing a specified number of threads or processes to access the resource simultaneously. The semaphore helps prevent race conditions and ensures orderly access to shared resources in a multithreaded or multiprocess environment.
- P stands for a wait operation. It reduces the value of counting semaphore by one for each wait operation.
- V stands for a signal operation. It increases the value of counting semaphore by one for each signal operation.
The current value of counting semaphore is 7. After performing 20P the value of counting semaphore becomes -13. Now 'n' V operations are to be performed, which makes the value of counting semaphore as 5.
The generated equation is like this: \(-13+n=5 => n=5+13 => n=18\)