Go for Infrastructure
Atomic operations
sync/atomic performs a read-modify-write on one value as a single indivisible operation.
What you will be able to do
- Explain why count++ races
- Decide when an atomic is enough and when a mutex is needed
What is in the lesson
- A real situation where this goes wrong
- How it works, step by step
- A command to try yourself
- How it fails in production, and how to tell
- Three quiz questions with explanations
Read this lessonFree. No account needed.
More in Go for Infrastructure
- WaitGroupsBeginner · 4 min
A WaitGroup lets a caller wait for a set of tasks to finish.
- Mutex and RWMutexBeginner · 4 min
A mutex coordinates access to shared state; an RWMutex permits multiple readers or one writer.
- Race detectorBeginner · 4 min
Go’s race detector reports certain unsynchronized accesses in code paths exercised by a run.
- Worker poolsBeginner · 4 min
A worker pool bounds concurrency with a fixed number of goroutines reading jobs from one channel.
- Bounded concurrencyBeginner · 4 min
Bounded concurrency limits how many operations are active while a separate queue holds waiting work.
- Backpressure in GoBeginner · 4 min
Explain backpressure in Go as a bounded channel or semaphore that makes fast producers wait, so queued work cannot grow memory without limit during a traffic spike.