Question: What is Mutex? Give software approaches for the same.

Mumbai University > COMPS > Sem 5 > Operating System

Marks: 10 M

Year: May 2015

modified 7 months ago by gravatar for Abhishek Tiwari Abhishek Tiwari50 written 3.2 years ago by gravatar for 0309rishika 0309rishika10

enter image description here

enter image description here

written 3.1 years ago by gravatar for 0309rishika 0309rishika10

Mutual Exclusion

  • Mutual exclusion is one of the conditions for a deadlock to occur.
  • It must be holding true for non-shareable resources .Non-sharable resources include printer, memory space etc.
  • The software approaches to mutual exclusion are:
  • Dekker’s algorithm
    • The basic fundamental that is used here is that only one access to a memory location can be made at a time.
    • Here we consider two process P0 and P1. We must impose an order of the activities of the two processes to avoid the problem of mutual courtesy. A variable turn is used for this purpose, which indicates which process has the right to insist on entering the CS.
    • When P0 wants to enter the CS, it sets the flag to true. It then checks for the flag of P1. If false, P0 enters the Critical section. Else P0 checks turn. If turn=0, It knows that it is its turn to insist and periodically check P1’s flag.
    • P1 at some instance will note that it’s time to defer and set its flag to false which will allow P0 to proceed.
    • After P0 has used its critical section, it sets flag to false to free the CS and sets turn to 1 to give P1 the right to insist.
  • Petersons Algorithm
    • The Dekker’s algorithm is a complex and tricky to prove method. Peterson provided a simple, elegant solution to it.
    • Flag variable indicates position of each process with respect to mutual exclusion
    • Turn variable resolves simultaneity conflicts.
    • Consider P0. Once it has set flag[0] to true, P1 cannot enter the its CS. If P1 is in its CS, then flag[1] is true and P0 cannot enter CS.
    • On the other hand, mutual blocking is prevented here.
    • Suppose P0 is in its while loop. Then flag[1] is true and turn=1. P0 can enter its CS when either flag[1] becomes false or turn becomes 0
    • Petersons algorithm is generalized to the case of n processes.
written 3.2 years ago by gravatar for 0309rishika 0309rishika10
Please log in to add an answer.