1 Assume that your computer has a swap xy instruction in its

(1) Assume that your computer has a swap x,y instruction in its machine language. This instruction can, as an atomic action, swap the contents of memory locations x and y (i.e. it cannot be interrupted). Show how this can be used to solve the mutual exclusion problem by writing the code for a process Pi such that when Pi is in its critical section, then no other processes are in theirs. Do not worry about a bounded waiting condition on your solution.

Solution

To use swap function to solve mutual exclusion problem we would need the following

Process Pi:
   repeat
      key:=1
      repeat
       swap(lock,key)
      until key=0;
       Critcal Section
      lock:=0;
       Remander Section
   until false
End Process

(1) Assume that your computer has a swap x,y instruction in its machine language. This instruction can, as an atomic action, swap the contents of memory locatio

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site