title: How does goroutines behave on a multi-core processor
body: <p>I am a newbie in Go language, so please excuse me if my question is very basic. I have written a very simple code:</p>
  
  <pre><code>func main(){
      var count int // Default 0
  
      cptr := &amp;count
  
      go incr(cptr)
  
      time.Sleep(100)
  
      fmt.Println(*cptr)
  }
  
  // Increments the value of count through pointer var
  func incr(cptr *int) {
      for i := 0; i &lt; 1000; i++ {
              go func() {
                      fmt.Println(*cptr)
                      *cptr = *cptr + 1
              }()
        }
      }
  </code></pre>
  
  <p>The value of count should increment by one the number of times the loop runs. Consider the cases:</p>
  
  <p>Loop runs for 100 times--> value of count is 100 (Which is correct as the loop runs 100 times).</p>
  
  <p>Loop runs for >510 times --> Value of count is either 508 OR 510. This happens even if it is 100000.</p>
  
  <p>I am running this on an 8 core processor machine.</p>