
Concurrency
Confinement and Ownership of Data Across Goroutines
Three ways to keep data private to one goroutine in Go: lexical confinement, partitioning a slice and ownership hand-off, with the race detector as the check.
8 min read
Tag
16 articles

Three ways to keep data private to one goroutine in Go: lexical confinement, partitioning a slice and ownership hand-off, with the race detector as the check.

What a goroutine leak is in Go, five patterns that cause most of them, how to find them with NumGoroutine and pprof, and how to fix them.

Go has no way to kill a goroutine, so ask it to stop: context, a done channel, closing its input, checks in CPU loops, unblocking I/O, and waiting.

How goroutines work in Go: the go statement, why main does not wait, what a goroutine costs in memory and time, closures, results and the mistakes to avoid.