Atomicity Violation: Lack of mutex inside critical section

Order Violation: Incorrect ordering of operations

Deadlock: Circular waiting

Deadlock Conditions

  1. Mutex: Only 1 process can use a resource
  2. Hold & Wait: Hold resources will waiting assignment for others
  3. No preemption: No resources can be forcibly removed from a process
  4. Circular Wait: Each process holds a resource that the next is waiting for

Deadlock Prevention

Deadlock Prevention: Break either one of the 4 conditions

Break Mutex: Use atomic hardware instructions that doesn’t need mutex

Break Hold & Wait

  1. Acquire all resources at once from start
  2. Trylock: Try to acquire lock A, if failed, release lock B and try again

Break No Preemption: Forcefully take a lock from a process

Break Circular Wait: Assign a linear order to resources ⭐️ (e.g. must lock R1 before R2)

Deadlock Detection: Use graph algorithms to detect deadlocks