If mutual exclusion is guaranteed, say, using semaphores, is a program without deadlocks?

I define mutual exclusion and deadlock, as shown below: A mutual exclusion condition exists if at every moment each shared resource is either assigned to exactly one process or is available. A set of processes is blocked if each process in the set expects an event that can only trigger another process in the set.

Say, binary semaphores are used to ensure that only one of them can simultaneously enter its critical area. Since each process performs an operation before entering its critical area and immediately after its exit, mutual exclusion is guaranteed.

I understand that there are four conditions that must be met for a dead end, one of which is the condition of mutual exclusion (none of the two processes can be simultaneously inside their critical sections).

Since mutual exclusion is guaranteed, the program in this case is not interdependent?

Sincerely.

+5
source share
1 answer

Not necessary. Imagine these two streams:

 Thread 1          Thread 2
 ============      =============
 Acquire A         Acquire B
 Acquire B         Acquire A
 Release B         Release A
 Release A         Release B

Here, mutual exclusion is really guaranteed - at each moment, semaphores A and B either belong to one of the threads or are accessible throughout the system, but deadlock is still possible if Thread 1 and 2 each acquire their first lock (A for Thread 1, B for Thread 2), but then there will be a dead end waiting for a resource that is holding another.

, !

+6

All Articles