edited by
211 views
0 votes
0 votes

Consider the following implementation as a solution to the critical section problem for two processes $\text{P}_{0}$ and $\text{P}_{1}$ with id $0$ and $1,$ respectively.

int flag[2] = {0,0};
    int turn = 0;

    void lock (int id)  /* id = 0 or 1 */
        {
            turn = id * 1;   /* S1 */
            flag[id] = 1;   /* S2 */
/* ‘^’ is the bitwise XOR */
            while (flag[id ^ 1]  && turn == (id ^ 1));
}

    void unlock (int id)
        {
            flag[id] = 0;
        }

Which of the following statements are correct?

  1. Mutual exclusion is guaranteed
  2. Mutual exclusion is guaranteed if $\text{S1}$ and $\text{S2}$ are interchanged
  3. Solution leads to a deadlock
  4. None of the above
edited by

Please log in or register to answer this question.

Answer:

Related questions