Deadlocks

This lesson gives an overview of deadlocks which might occur during implementation of concurrency in C++.

A deadlock is a state in which two or more threads are blocked because each thread waits for the release of a resource before it releases its own resource.

There are two main reasons for deadlocks:

  1. A mutex has not been unlocked.
  2. You lock your mutexes in a different order.

For overcoming the second issue, techniques such as lock hierarchiesDesigning your application so that mutexes can only be locked in a particular sequence is called a lock hierarchy. This restriction may not always be realistic for some applications, but it potentially prevents deadlocks in the cases where it applies. are used in classical C++.

For the details about deadlocks and how to overcome them with modern C++, read the subsection issues of mutexes and locks.

Get hands-on with 1200+ tech skills courses.