Why locks typically have worse performance than atomics?

Jun 17, 2025

Why locks typically have worse performance than atomics?

The main reason is that locks can rely on syscalls like futex to put threads to sleep when there’s contention, which introduces overhead such as context switches. In contrast, atomic operations are low-level CPU instructions executed entirely in user space, avoiding these costly transitions. Additionally, locks tend to serialize access to larger critical sections, while atomics enable more fine-grained concurrency, reducing contention and improving performance in many scenarios.

#concurrency #locks #atomics #performance