Modern computers have many CPU cores. A serial program — one that does one thing at a time — uses only a fraction of the hardware available. Concurrency is the art of writing programs that do multiple things at once, and Go was specifically designed to make this easy.
This section is what makes Go famous. The features here — goroutines, channels, and Go’s synchronization primitives — are why companies pick Go for high-throughput, networked services.
What’s in this section
- Goroutines and Channels — Go’s lightweight threads and the communication mechanism between them
- Synchronization —
sync.Mutex,sync.RWMutex, andsync.Oncefor the cases where channels aren’t the right fit
A note before we begin: concurrency is hard. Even with Go’s tools, race conditions and deadlocks are real and can be subtle. Take these lessons slowly. Run the examples. Modify them. Break them. The intuition you build is more valuable than the syntax you memorize.