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.
Activity Over Time
Top Contributors
Keywords
Sample Comments
Atamic operations have some overhead.
`atomic` may require a lock, depending on the CPU.
Honest question: why would atomics be necessary or useful if data isn’t shared between threads?
Why do you need atomics on a single core device?
It would be if you used atomics.
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.
How is CAS guaranteed to be atomic? Is it actually implemented by a machine instruction, rather than the pseudocode in the article?
RAM doesn’t really provide atomic reads and writes without additional semantics in most cases? (Locking)
Yes, but atomics are pretty slow.
You can use RCpc atomics which are part of the standard architecture