This tutorial covers the fundamentals of concurrent programming with examples in Go.
Before you start, you need to know how to write basic Go programs. If you need a refresher, the resources in Get started with Go will help you come up to speed quickly with Go.
Table of contents
A goroutine is a lightweight thread of execution. All goroutines in a single program share the same address space.
A channel is a mechanism for two goroutines to synchronize execution and communicate by passing values.
A select statement allows you to wait for multiple send or receive operations simultaneously.
A data race is easily introduced by mistake and can lead to situations that are very hard to debug. This article explains how to avoid this headache.
Detect data races
By starting your application with the '-race' option, the Go runtime might be able to detect and inform you about data races.
The Go runtime can often detect when a program freezes because of a deadlock. This article explains how to debug and solve such issues.
Waiting for goroutines
A sync.WaitGroup waits for a group of goroutines to finish.
Broadcast a signal on a channel
When you close a channel, all readers receive a zero value. This can be used to broadcast a signal to several goroutines on a single channel.
How to kill a goroutine
One goroutine can't forcibly stop another. To make a goroutine stoppable, let it listen to a stop signal on a channel.
Timer and Ticker: events in the future
Timers and Tickers are used to wait for, repeat, and cancel events in the future.
Mutual exclusion lock (mutex)
A sync.Mutex is used to synchronize data by explicit locking in Go.
Efficient parallel computation
To efficiently schedule parallel computation on separate CPUs is more of an art than a science. This article gives some rules of thumb.
Go gotcha is a collection of common mistakes in Go intended to help you spot similar traps in your own code and save you time when debugging.
Share this page: Email | Twitter | Facebook | Reddit