Skip to content
Commitwise
Menu

Data race

Also called: Race condition

Two threads accessing the same memory at the same time, at least one of them writing, without synchronization.

Definition

Data races corrupt memory and cause crashes or wrong results that are rare, unpredictable and hard to reproduce, because they depend on exact timing. Locks, actors, immutable data and confining state to one thread all prevent them. Swift 6 rejects code that could race at compile time; on the JVM, tools and careful design (immutable objects, concurrent collections) are the main defense.

In practice

Two tasks writing to the same Swift Dictionary inside a plain class can crash inside the dictionary's code once in thousands of runs.

Related terms

Esc

Type to search the whole site.