Multicore & Synchronization

Which is an example of deadlock?

  1. AThread 1 holds lock A and waits for lock B, while thread 2 holds lock B and waits for lock A
  2. BTwo threads update the same variable without synchronization and corrupt it
  3. COne thread acquires a lock and releases it immediately
Show answer and explanation

Answer: A. Thread 1 holds lock A and waits for lock B, while thread 2 holds lock B and waits for lock A

Deadlock is a state in which threads each hold a resource while waiting for one held by another, so none can proceed. In the example, thread 1 waits for B to be released and thread 2 waits for A, but neither gives up its own lock, so both stop forever. With locks that sleep while waiting, they stop without using the CPU, so the program simply appears frozen.

  • A. Correct. Each waits on the other forever.
  • B. That is a data race.
  • C. That is normal, harmless use.