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 valStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started