TECH Signal 524 2 feeds carried it
Unsynchronized goroutine writes in Go risk infinite loops and torn reads under the memory model
A detailed post explains that Go does not guarantee visibility of unsynchronized writes across goroutines, risking infinite loops and torn multi-word values.
Code that passes values between goroutines using simple flags without channels or atomic operations can fail silently. The compiler may optimize away repeated reads of the flag, and multi-word types like strings or structs can be read in an inconsistent state.
Written by elseif from the cluster below · every claim links back to a sourceThe three things worth knowing
The Go race detector flags unsynchronized concurrent access to shared variables, even if the program appears to work correctly.
The Go memory model permits the compiler to optimize loops by reading a flag only once, potentially causing an infinite loop if the write is never seen.
Multi-word values such as strings, slices, and structs can be read or written in parts during a data race, leading to inconsistent state or memory corruption.
THE CLUSTER
↗