News for hackers. Stuff that matters.
Re:There's No Such Thing as “Implicitly Atomic” by felixge on Thursday October 05, 2023 @01:37PM (#37781507)
The Go runtime has quite a few places where it assumes atomic load/store behavior of int sized words.

I always get a little anxious when looking at such code. But it seems to work well in practice?

Re:There's No Such Thing as “Implicitly Atomic” by colesbury on Thursday October 05, 2023 @01:43PM (#37781588)
Go's memory model is more constrained than C, C++, and Swift and this case is specifically addressed: https://go.dev/ref/mem#restrictions.

"...each read of a single-word-sized or sub-word-sized memory location must observe a value actually written to that location"

Re:There's No Such Thing as “Implicitly Atomic” by felixge on Thursday October 05, 2023 @02:40PM (#37782351)
Yeah, but there is no guarantee that a write of one goroutine will eventually become visible to other goroutines. So in practice the runtime expects stronger guarantees.
Re:There's No Such Thing as “Implicitly Atomic” by colesbury on Thursday October 05, 2023 @05:33PM (#37784564)
Memory models don't usually explicitly guarantee that writes "eventually become visible". They're usually written as ordering guarantees for when a write becomes visible, such as happens-before relationships. Obviously, for multithreaded programs to be useful, the writes have to eventually become visible to other threads/groroutines just like you want all sorts of other operations to happen in finite time that are not explicitly guaranteed by standards (like whether a thread/goroutine eventually starts.)
Re:There's No Such Thing as “Implicitly Atomic” by felixge on Friday October 06, 2023 @03:54AM (#37788204)
Well said. But how much finite time are we talking about (for writes to become visible)? Does it differ between architectures? Can there be extreme edge cases?
Re:There's No Such Thing as “Implicitly Atomic” by compiler-guy on Thursday October 05, 2023 @02:46PM (#37782441)
Anyone who writes a compiler for Go can guarantee such behavior--anything else is a buggy implementation.

It works in practice because it's a requirement of the implementation.

Re:There's No Such Thing as “Implicitly Atomic” by felixge on Thursday October 05, 2023 @02:59PM (#37782665)
I guess I’m less worried about the atomic nature of the operation and more about the way the writes become visible. That seems to be entirely hardware dependent?