Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

2-1. What are six characteristics of effective teams? [LO-1]

Answered: 1 week ago