Question: We have seen a pseudocode implementation of counting semaphores. The semaphore value in the original example, which is repeated here, was not allowed to become
We have seen a pseudocode implementation of counting semaphores. The semaphore value in the original example, which is repeated here, was not allowed to become negative. Assume we can allow the semaphore value to be negative, provide a new implementation of the semaphore wait() and signal(). The first line of the code in the new implementation of wait() and signal() are given (and cannot be changed).
[5] We have seen a pseudocode implementation of counting semaphores. The semaphore value in the original example, which is repeated here, was not allowed to become negative. Assume we can allow the semaphore value to be negative, provide a new implementation of the semaphore wait() and signal(). The first line of the code in the new implementation of wait() and signal() are given (and cannot be changed). Original: wait(s) { if (S.val > 0) S.val--; else wait until allowed to proceed; } signal(s) { if (processes wait on S) allow one to proceed; else S.val++; } New: wait(s) { S.val; signal(s) { S.val++; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
