liveBook · Manning

Safe state

As explained in Learn Concurrent Programming with Go

A safe state is a resource-allocation state from which there is an execution schedule allowing every execution to complete even if each requests its maximum resources.

A safe state is a resource-allocation state with an execution schedule that lets every execution complete, even after requesting its maximum resources. An unsafe state lacks such a schedule and risks deadlock. section 11.2.2

The Banker’s algorithm evaluates a requested allocation using:

  • Each execution’s maximum possible request. section 11.2.2
  • The resources currently held by each execution. section 11.2.2
  • The number of resources currently available. section 11.2.2
  • Grant a request only when the resulting state remains safe; otherwise suspend the requesting execution. section 11.2.2

Database connection pool

With a fixed pool of database sessions, granting execution a another session can create an unsafe state when the remaining resources cannot satisfy executions a, b, and c. The original allocation remains safe if some completion schedule still exists. section 11.2.2

Figure 11.10 Examples of safe and unsafe state scenarios

Compare the safe and unsafe resource-allocation scenarios. section 11.2.2

How Learn Concurrent Programming with Go covers it

How deep it goes
Defines schedulability and allocation criteria, but does not derive the Banker’s algorithm step by step.
Examples
Illustrates safe states with database connection pools and contrasting resource-allocation scenarios.
What it assumes
Assumes resource requests, current holdings, maximum demands, and available resources can be identified.
What you can do after
Evaluate whether granting a resource request preserves a schedule in which every execution can complete.
How it connects
Connects safe states with deadlock, resource allocation, and the Banker’s algorithm.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Concurrent Programming with Go. The section links point to the parts of the book it draws on.