title: Can I concurrently write different slice elements
body: <p>I have a slice that contains work to be done, and a slice that will contain the results when everything is done. The following is a sketch of my general process:</p>
  
  <pre><code>var results = make([]Result, len(jobs))
  wg := sync.WaitGroup{}
  for i, job := range jobs {
      wg.Add(1)
      go func(i int, j job) {
          defer wg.Done()
          var r Result = doWork(j)
          results[i] = r
      }(i, job)
  }
  wg.Wait()
  // Use results
  </code></pre>
  
  <p>It seems to work, but I have not tested it thoroughly and am not sure if it is safe to do. Generally I would not feel good letting multiple goroutines write to <em>anything</em>, but in this case, each goroutine is limited to its own index in the slice, which is pre-allocated. </p>
  
  <p>I suppose the alternative is collecting results via a channel, but since order of results matters, this seemed rather simple. Is it safe to write into slice elements this way?</p>