Atomic Operations Concurrency

Discussions center on the performance overhead, necessity, implementation details like CAS, and alternatives such as locks for atomic operations in multithreaded and single-core programming contexts.

➡️ Stable 0.6x Programming Languages
2,048
Comments
20
Years Active
5
Top Authors
#4124
Topic ID

Activity Over Time

2007
1
2008
1
2009
14
2010
30
2011
44
2012
35
2013
55
2014
72
2015
106
2016
175
2017
119
2018
60
2019
131
2020
139
2021
185
2022
232
2023
219
2024
181
2025
240
2026
9

Keywords

RAM XB1 RC CPU ARM ABA CAS AMD swift.org BTW atomic operations threads thread locks shared writes acquire swap cas

Sample Comments

rightbyte Jul 1, 2022 View on HN

Atamic operations have some overhead.

ape4 Dec 5, 2016 View on HN

`atomic` may require a lock, depending on the CPU.

cdogl Jun 18, 2023 View on HN

Honest question: why would atomics be necessary or useful if data isn’t shared between threads?

Scaevolus Nov 22, 2020 View on HN

Why do you need atomics on a single core device?

saagarjha Jan 19, 2026 View on HN

It would be if you used atomics.

zaphar Jun 29, 2022 View on HN

You need more than just atomic access I think. You need an atomic compare and swap. These are usually a hardware affordance. To properly use them most languages provide an atomic int that expose the hardware version in an ergonomic interface. This is then typically wrapped in a Mutex library that exposes an even more ergonomic interface than the atomic primitive. You can sometimes rely just on the atomic primitive if that's all you need but most of the time you need more.

dmoney Aug 29, 2009 View on HN

How is CAS guaranteed to be atomic? Is it actually implemented by a machine instruction, rather than the pseudocode in the article?

lazide Aug 13, 2022 View on HN

RAM doesn’t really provide atomic reads and writes without additional semantics in most cases? (Locking)

iainmerrick Dec 3, 2016 View on HN

Yes, but atomics are pretty slow.

saagarjha Nov 20, 2024 View on HN

You can use RCpc atomics which are part of the standard architecture