Skip to content

Safety failure

Category: Hazards · Status: stub · Lessons: chapter 02, Shared state

One line: The program reaches a state it must never reach — a lost update, a torn read, a broken invariant — usually because two tasks interleaved badly.

Also called: data inconsistency, lost update, torn read.

How it connects

flowchart LR
  n_data_race["Data race"]
  n_race_condition["Race condition"]
  n_safety_failure["Safety failure"]
  n_data_race -->|is a| n_safety_failure
  n_race_condition -->|is a| n_safety_failure
  classDef center stroke-width:3px
  class n_safety_failure center
  classDef outside stroke-dasharray: 4 3
  class n_data_race,n_race_condition outside

In each language

Go The Go memory model ↗ warns that races on multiword values can lead to arbitrary memory corruption; since Go 1.6 ↗ the runtime has best-effort detection of concurrent misuse of maps
Java ArrayList is not synchronized, and its fail-fast iterators throw ConcurrentModificationException only on a best-effort basis
Python Library FAQ ↗: some operations on built-in types are atomic, but a read-modify-write such as i = i+1 is not

Where to read more