Let be mutexes (binary semaphores) and be processes.
Suppose each process executes the following:
wait (m[i]); wait (m(i+1) mod 4]);
...........
release (m[i]); release (m(i+1) mod 4]);
This could cause
View worked solution
Answer: B
This problem is a variation of the classic Dining Philosophers Problem, which can lead to a deadlock due to circular wait.
Let us analyze the resource acquisition sequence for the processes and using the mutexes .
Each process attempts to acquire resources in the following order:
- First, it locks .
- Then, it attempts to lock .
Consider the following execution sequence for the first four processes to :
- executes
wait(m[0])and successfully acquires . - executes
wait(m[1])and successfully acquires . - executes
wait(m[2])and successfully acquires . - executes
wait(m[3])and successfully acquires .
Now, each process attempts to acquire its second mutex:
- attempts
wait(m[1])and is blocked because is held by . - attempts
wait(m[2])and is blocked because is held by . - attempts
wait(m[3])and is blocked because is held by . - attempts
wait(m[0])(since ) and is blocked because is held by .
This creates a closed cycle of dependency:
Since all four conditions for deadlock (Mutual Exclusion, Hold and Wait, No Preemption, and Circular Wait) are satisfied, this execution sequence results in a deadlock.
Free practice · Your answers on this page are not saved.
