Question

Operating Systems how do semaphores support mutual exclusion ?

Operating Systems

how do semaphores support mutual exclusion ?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:-

First of all semaphore is variable used to solve critical section problem.

There are two operations in semaphores. one is wait() and another one is signal()

implementation of wait:-

wait(Semaphore s)

{

            while(s==0);   //wait untill s==0//

s = s-1                 //decrements semaphore value

}

implementation of signal:-

signal(Semaphore s)

{

     s = s+1;

}

support for mutual exclusion through semaphore:-

first of all semaphore initialized to 1 and p1 and p2 are two processes

step1:-   s=1 p1,p2 //not in critical section//

step2:- if p1 enters into critical section.

             it will call wait() operation

             then s =0

step3:- another process p2 can not enter critical section until p1 calls signal opeartion //supports mutual exclusion//

step4:- p1 completes its operation then calls signal() function

step:-now s=1 then p2 can enter critical section.

process will implement following procedure for mutual exclusion:-

while(True)

{

//non critical section//

wait(s);

//critical section//

signal(s);

}

Add a comment
Know the answer?
Add Answer to:
Operating Systems how do semaphores support mutual exclusion ?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT