3 ms·
We use atomic operations to update the pointers in a thread-safe manner Are you sure about that? Atomics are not locks, and not all systems have strong memory
by cperciva 2y ago
We use atomic operations to update the pointers in a thread-safe manner
Are you sure about that? Atomics are not locks, and not all systems have strong memory ordering.
- jpc0 2y ago> ... update the pointers ... Pretty sure ARM and x86 you would be seeing on AWS does have strong memory ordering, and has atomic operations that operate on something the size of a single register...
- cperciva 2y agoGraviton has weaker memory ordering than amd64. I know this because FreeBSD had a ring buffer which was buggy on Graviton...
- Sesse__ 2y agoRust atomics, like C++ atomics, include memory barriers (the programmer chooses how strong, the compiler/CPU is free to give stronger).
- CodesInChaos 2y ago> not all systems have strong memory ordering Atomics require you to explicitly specify a memory ordering for every operation, so the system's memory ordering doesn't really matter. It's still possible to get it wrong, but a lot easier than in (traditional) C.
- reitzensteinm 2y agoIt's still possible to incorrectly use relaxed operations, and have your algorithm only incidentally work because the compiler hasn't reordered them and you're on a CPU with a stronger memory model. But yes, it's an order of magnitude easier to get portability right using the C++/Rust memory model than what came before.
- CyberDildonics 2y agoA huge part of atomic operations in programming languages and modern CPUs (meaning in the last few decades) is updating pointers in a thread safe manner. Why would think you need locks?