Question: Implement the counting semaphores using binary semaphores. Pseudo-code for the implementation is given below. In your main(), spawn three threads; in each thread function, you
Implement the counting semaphores using binary semaphores. Pseudo-code for the implementation is given below. In your main(), spawn three threads; in each thread function, you will need a call to wait(counting_semaphore) and signal(counting_semaphore). For the critical section, you can just have sleep() to make the thread wait for some time. The incorrect implementation output from the attached notes will help you in writing the code. Turn in the output for BOTH the incorrect and correct implementations. Attach codes (two versions: for incorrect and correct solutions).
Two implementations of counting semaphores using binary semaphores are given below. Implementation 1 is incorrect. Implementation 2 is proved to be correct.
Assignment is . Equality is "=". CSem stands for counting semaphores. BSem stands for binary semaphores.



2 Implementation 1 (incorrect) CSem(K) cs I7 counting sem, init K int val K: // value of csem BSem wait(0): // to block on csem BSem mutex(1); // protects val Pc(cs) C Evolution showing error P(mutex); val val - 1; if val
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
