574 views
1 votes
1 votes

Consider the atomic exchange instruction defined as follows:

void exchange (int *a, int *b)
{
   int temp;
   temp = *b;
   *b = *a;
   *a = temp;
}
Now consider the solution to critical section problem based on above instruction:
 
    1   int const n = /* number of processes */;
    2   int lock = 0;
    3   void P(int i)
    4   {
    5      int key = 1; //intent to obtain lock
    6      while (true)
    7      {
    8         do exchange (&key, &lock)
    9         while (key != 0); //if lock wasn’t free
    10        /* critical section */;
    11        lock = 0;   //release lock, unblock
    12                    //other processes
    13        /* remainder */;
    14     }
    15  }
    16  void main()
    17  {
    18     lock = 0;
    19     parbegin (P(1), P(2), ..., P(n));
    20  }
 
Does the above code meets bounded waiting and progress requirements of critical section problem?

1 Answer

Related questions

0 votes
0 votes
2 answers
1
shivajikobardan asked Jul 22, 2023
729 views
Sorry if this is a stupid question. But it really intrigued me. Same resources at different algorithms are telling different ways to test these stuffs.Here's an algorith...
9 votes
9 votes
2 answers
2
3 votes
3 votes
4 answers
3
agoh asked Dec 11, 2016
1,091 views
My doubt is as follows: If deadlock is there, processes will be busy waiting in wait loop. So, decision on which process enters C.S. is not made in finite time. Hence, is...