Goroutines: the dark side of the runtime
summary
Explains that goroutines run on a fixed number of OS threads via the M P G scheduler, shows a real example where a loop with a closure capturing loop variable prints ten identical values, and demonstrates a subtle live lock where a tight for loop with an outer byte counter prevents GC because goroutines are preemption only at safe points, causing endless garbage collection. Shows practical fixes: copy loop vars, introduce checkpoints (channel ops, go, noinline), and adopt context for cooperative cancellation, while noting the runtime cannot forcibly kill goroutines.
AI-written summary · about
chapters (10)
- 0:00Intro
- 1:50Why Go
- 3:04Surprises
- 11:20MGP model
- 13:45Issues with goroutines
- 16:20The trick
- 20:12Debugging
- 23:11Stop a goroutine
- 24:45PHP
- 30:15QA
related talks
22mTales of Go Runtime Scheduler
46mGoing Loopy: Iteration in Go
29mGo Surgery: a Goroutine and Its Innards
30mMemory Management in Go: The good, the bad and the ugly
40mDebugging concurrency programs in Go
16mIn the land of Gophers from age 3
49mDeep dive into the Go scheduler, or Why would I steal goroutines?
56mThe Key to Go Efficiency is Just a Few Go Runtime Metrics Away!
