4 ms·
Interestingly, the Go memory model[1] does in fact guarantee atomicity of word-sized reads/writes: > Otherwise, each read of a single-word-sized or sub-word-si
by sapiogram 3y ago
Interestingly, the Go memory model[1] does in fact guarantee atomicity of word-sized reads/writes:
> Otherwise, each read of a single-word-sized or sub-word-sized memory location must observe a value actually written to that location (perhaps by a concurrent executing goroutine) and not yet overwritten.
However, it allows the implementation to immediately exit and report an error as well.
[1]: https://go.dev/ref/mem https://go.dev/ref/mem
- andrewaylett 3y agoWhile Rust won't let you share a non-atomic variable across threads without going through a lock of some form or using `unsafe`. So for both Rust and Go you'll get atomic accesses when you need them, and for C etc you only get atomic accesses if you ask for them. Which pretty much speaks to the different programming models: Rust and Go will only compile the subset of possibly-valid programs that can be expressed by the language and proven by the compiler. C compilers will only reject code they can prove is incorrect.