11 Avoiding deadlocks

This chapter covers

  • Identifying deadlocks
  • Avoiding deadlocks
  • Deadlocking with channels

A deadlock, in a concurrent program, occurs when executions block indefinitely, waiting for each other to release resources. Deadlocks are an undesirable side effect of certain concurrent programs where concurrent executions are trying to acquire exclusive access to multiple resources at the same time. In this chapter, we will analyze the conditions under which deadlocks might occur and offer strategies to prevent them. We’ll also discuss certain deadlocking conditions that can occur when using Go channels.

Deadlocks can be quite tricky to identify and debug. As with race conditions, we can have a program that runs without hitches for ...

Get Learn Concurrent Programming with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.