Goroutine’i “ucuz thread” diye özetlemek yaygın ama eksik. Runtime scheduler, M:N modeliyle binlerce goroutine’i az sayıda OS thread üzerinde çalıştırır.
Ne değildir?
- Bire bir OS thread değildir.
- Node.js callback’i değildir.
- Python async coroutine’inin birebir aynısı değildir (stack’li, senkron yazım).
Minimal örnek
go
package main
import (
"fmt"
"sync"
)
func main() {
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
fmt.Println("ben arka plandayım")
}()
wg.Wait()
}Dikkat
main bitince tüm goroutine’ler ölür. WaitGroup veya channel ile bekle.Temel eğitim: 16. Goroutine dersi ve 17. Channel.