IT lexicon › Programming › Thread safety

Thread safety

Programming På svenska → Updated: 2026-11-16

Property of code that can be safely executed by multiple threads simultaneously without corrupting shared data.

A function or data structure is thread-safe if all concurrent accesses from multiple threads leave the system in a consistent state. It can be achieved through locking, atomic operations, or by avoiding shared data altogether. The opposite is a race condition, where two threads read or write the same value without synchronization.

Thread safety is often a design question rather than a choice — is the data read-only? Does it belong to a single thread? Or is it shared within critical sections? Languages approach it differently: Go encourages communication through channels, Rust uses compile-time guarantees.

← Back to the lexicon