Deadlock

A deadlock is a condition where a program cannot access a resource it needs to continue. When an active application hits a deadlock, it may "hang" or become unresponsive.

Resources, such as saved or cached data, may be locked when accessed by a specific process within a program. Locking the data prevents other processes from overwriting the data prematurely. If a process or query needs to access locked data, but the process locking the data won't let it go, a deadlock may occur.

For example, the following situation will cause a deadlock between two processes:

  • Process 1 requests resource B from process 2.
  • Resource B is locked while process 2 is running.
  • Process 2 requires resource A from process 1 to finish running.
  • Resource A is locked while process 1 is running.

The result is that process 1 and process 2 are waiting for each other to finish. Since neither process can continue until the other one completes, a deadlock is created.

Avoiding Deadlocks

Developers can prevent deadlocks by avoiding locking conditions in their programming logic. For example, instead of having two processes rely on each other, the source code can be written so that each thread finishes before another thread needs its resources. By ensuring data is accessible when needed, programmers can protect their applications from hanging or crashing.

NOTE: Deadlocks may also occur when two or more queries are run on a database. Transactional databases lock active records, preventing other queries from accessing them. If a process cannot access a locked record, a database deadlock may occur.

Updated January 18, 2020

Definitions by TechTerms.com

The definition of Deadlock on this page is an original TechTerms.com definition. If you would like to reference this page or cite this definition, you can use the green citation links above.

The goal of TechTerms.com is to explain computer terminology in a way that is easy to understand. We strive for simplicity and accuracy with every definition we publish. If you have feedback about the Deadlock definition or would like to suggest a new technical term, please contact us.

Want to learn more tech terms? Subscribe to the daily or weekly newsletter and get featured terms and quizzes delivered to your inbox.

Sign up for the free TechTerms Newsletter

How often would you like to receive an email?

You can unsubscribe or change your frequency setting at any time using the links available in each email.

Questions? Please contact us.