All posts
Goroutines vs Threads, Explained With Boda Bodas
Threads are buses: big, expensive and slow to start. Goroutines are boda bodas — cheap, nimble and there are thousands of them.
Kampala Gophers Team3 min read
Imagine Kampala's traffic. An OS thread is a bus: it carries a lot, but it takes up a lane, costs a fortune to run and you can only have so many. A goroutine is a boda boda — tiny, cheap to start, and the Go scheduler weaves thousands of them through a handful of lanes (OS threads).
func deliver(orders []Order) {
var wg sync.WaitGroup
for _, o := range orders {
wg.Add(1)
go func(o Order) {
defer wg.Done()
ride(o) // each delivery gets its own boda
}(o)
}
wg.Wait()
}The scheduler (the stage chairman, if you like) decides which boda moves next. You just describe the work.
// Weekly Intel
Get the next post in your inbox
Event updates and the occasional Go deep-dive. No spam, unsubscribe any time.