package main
import (
//"time"
"runtime"
"fmt"
)
func main() {
//time.Sleep(100 * time.Millisecond)//By adding this number of goroutine increases
fmt.Println(runtime.NumGoroutine())
}
I am trying to find out the number of goroutines in a program. My code is here. While coding this I noticed default number of goroutines is 4.
For me:
- main is one goroutine
- garbage collector is one goroutine
What are the others?
By adding the time.Sleep (above), the number of goroutines increases to 5. What is the reason for this?