Q40: Problem with software lock based solution to critical section problem

Question 40: Consider the following solution for critical section problem:

while (lock == 1);
lock = 1;
//Critical section
lock = 0;

Which of the following conditions are not held for the above solution of critical section problem:

A) No two processes may be simultaneously inside their critical regions.

B) No assumptions should be made about speeds or the number of CPUs.

C) No process running outside its critical region may block other processes.

D) No process should have to wait forever to enter its critical region.

 

Solution:

There is a race condition in the above solution. It is possible that the first process checks the while condition and finds that lock is 0. Then, context switch happens and the other process also finds that lock is 0, now both of the processes are in the critical region. Hence, the correct answer is A.