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.
Find output for BOTH the incorrect and correct implementations. Also, attach your codes (two versions: for incorrect and correct solutions)
 Implement the counting semaphores using binary semaphores. Pseudo-code for the implementation

2 Implementation 1 (incorrect) CSentK) escount ing sen, init K int val K: //value of cset BSem waito): to block on csem BSem nutext1): / protects val Peics) C Evolation showing error nitial: if val 0: 0 1f val0 BSee nutex(1) If protects va Pctcs)C P(gate) al: Knutex); vval-1 if val > 0 Vgate): Pnute): val+1: f val VCgate)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!