Locks vs Lock-Free

This cluster discusses the performance, use cases, and trade-offs of locks (mutexes, spinlocks) versus lock-free algorithms and atomics in concurrent programming, including when one outperforms the other and common pitfalls like contention.

➡️ Stable 0.6x Programming Languages
5,200
Comments
20
Years Active
5
Top Authors
#1442
Topic ID

Activity Over Time

2007
1
2008
13
2009
27
2010
76
2011
96
2012
144
2013
152
2014
214
2015
212
2016
380
2017
279
2018
210
2019
376
2020
480
2021
366
2022
464
2023
574
2024
537
2025
588
2026
11

Keywords

CPU ImplementingCVs.pdf threading.Lock POSIX NOT RwLocks OS birrell.org MSVC NPE locks lock locking pointer grained atomic free spin fine grained synchronization

Sample Comments

anhldbk • Jun 2, 2017 • View on HN

In which circumstances, lock-free algorithms are NOT better than locking ones?

sweetjuly • Jun 18, 2023 • View on HN

locks and mutexes will perform worse than things like atomic increment.

bouk • Jun 21, 2016 • View on HN

Seems like this is what mutexes were invented for

amelius • Dec 15, 2014 • View on HN

what are alternatives to mutexes? I find them a software engineering disaster waiting to happen.

quickthrower2 • Jul 21, 2022 • View on HN

Doesn’t the need for locks make it incredibly slow?

imtringued • Apr 1, 2024 • View on HN

From what I have heard they use manual spin locks. Generally, spin locks are not a good idea unless you want to dedicate the entire machine to a single application. If the process a spinlock waits on gets suspended, you're burning CPU time for nothing. The OS thinks a spinlock making zero progress is actually a high priority process, so it is starving the suspended process from making progress.

jkot • Aug 10, 2016 • View on HN

Spin locks are not very power efficient.

azth • Nov 16, 2015 • View on HN

Aren't they "lock-free" though?

koakuma-chan • Sep 29, 2025 • View on HN

Why would lockless be slower? Is it ever slower?

jstx1 • Apr 6, 2023 • View on HN

What's the problem with mutexes?