Question

The below pseudocode shows functions p1 and p2, used by two separate processes. These processes share two mutexes, m1 and m2.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. Mutexes is a piece of code written in entry section of a program which will lock the shared resource not to be used by any other program/process until the process critical section is completely executed. In other words we can say that mutex is implemented to prevent a programs getting into a Race condition.

2. This code will run into deadlock situation as both the programs is trying to access resource R2 simultaneously. In this code function P1 is using a resource R1 already and requires another resource but the at the same time function P2 is holding resource R2 and therefore a deadlock situation is getting arrived.

When process P1 is passing second lock m2 for accessing resource R2 at the same time process P2 is trying to lock 2nd resource. This is exactly where the deadlock situation is getting arrived

3. This best way to avoid deadlock problem is to make sure whenever different processes lock multiple mutexes,they should do in the same order . When locks are taken in prescribed order ,deadlock will not arrive.

so process P2 should be written as mentioned below

void P2(){

atomic_lock (&m1);

atomic_lock(&m2);

// run critical region...

unlock (&m1);

unlock(&m2);

}

Add a comment
Know the answer?
Add Answer to:
The below pseudocode shows functions p1 and p2, used by two separate processes. These processes share...
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