←back to thread

261 points tosh | 6 comments | | HN request time: 0.42s | source | bottom
1. cperciva ◴[] No.42069585[source]
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.

replies(3): >>42070126 #>>42070474 #>>42070917 #
2. jpc0 ◴[] No.42070126[source]
> ... 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...

replies(1): >>42070251 #
3. cperciva ◴[] No.42070251[source]
Graviton has weaker memory ordering than amd64. I know this because FreeBSD had a ring buffer which was buggy on Graviton...
4. Sesse__ ◴[] No.42070474[source]
Rust atomics, like C++ atomics, include memory barriers (the programmer chooses how strong, the compiler/CPU is free to give stronger).
5. CodesInChaos ◴[] No.42070917[source]
> 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.

replies(1): >>42071585 #
6. reitzensteinm ◴[] No.42071585[source]
It'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.