title: How many goroutines are started by default in a Go program?
body: <pre><code>package main
  
  import (
      //"time"
      "runtime"
      "fmt"
  )
  
  func main() {
      //time.Sleep(100 * time.Millisecond)//By adding this number of goroutine increases
  fmt.Println(runtime.NumGoroutine())
  }
  </code></pre>
  
  <p>I am trying to find out the number of goroutines in a program. My <a href="http://play.golang.org/p/oDNYtyHxK5" rel="nofollow">code is here</a>. While coding this I noticed default number of goroutines is 4.</p>
  
  <p>For me:</p>
  
  <ul>
  <li>main is one goroutine</li>
  <li>garbage collector is one goroutine</li>
  </ul>
  
  <p>What are the others?</p>
  
  <p>By adding the <strong>time.Sleep</strong> (above), the number of goroutines increases to 5. What is the reason for this?</p>