Multicore & Synchronization
Which is an example of deadlock?
- AThread 1 holds lock A and waits for lock B, while thread 2 holds lock B and waits for lock A
- BTwo threads update the same variable without synchronization and corrupt it
- 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. Because they stop without using the CPU, 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.