Atomic operations composition in Go
An atomic operation in a concurrent program is a great thing. Such operation usually transforms into a single processor instruction, and it does not require locks. You can safely call it from different goroutines and receive a predictable result.But what happens if you misuse atomics? Let's figure it out.AtomicityCompositionSequence-independenceFinal thoughtsAtomicityLet's look at a function that increments a counter:var counter int32
func increment() {
counter += 1
// random sleep up to 10 ms
s...
Read more at antonz.org