title: Parallel processing in golang
body: <p>Given the following code:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "math/rand"
      "time"
  )
  
  func main() {
      for i := 0; i &lt; 3; i++ {
          go f(i)
      }
  
      // prevent main from exiting immediately
      var input string
      fmt.Scanln(&amp;input)
  }
  
  func f(n int) {
      for i := 0; i &lt; 10; i++ {
          dowork(n, i)
          amt := time.Duration(rand.Intn(250))
          time.Sleep(time.Millisecond * amt)
      }
  }
  
  func dowork(goroutine, loopindex int) {
      // simulate work
      time.Sleep(time.Second * time.Duration(5))
      fmt.Printf("gr[%d]: i=%d\n", goroutine, loopindex)
  }
  </code></pre>
  
  <p>Can i assume that the 'dowork' function will be executed in parallel?</p>
  
  <p>Is this a correct way of achieving parallelism or is it better to use channels and separate 'dowork' workers for each goroutine?</p>