Atomic Operations Composition in Go

by boyteron 6/25/24, 10:41 PMwith 3 comments
by chen_devon 6/25/24, 11:31 PM

> People sometimes think that the composition of atomics also magically becomes an atomic operation. But this is not the case.

> var counter atomic.Int32

> func increment() {

> if counter.Load()%2 == 0 {

> sleep(10)

> counter.Add(1)

> } else {

> sleep(10)

> counter.Add(2)

> }

> }

Is "atomic operations composition" a real term? Or it's something like "monolithic microservice"? What does that even mean?