title: Use mutex or mutex pointer in Golang?
body: <p>I have a code snippet:</p>
  <pre><code>type calculation struct{
      sum int
      mutex sync.Mutex
  }
  
  func dosomething(c *calculation , wg *sync.WaitGroup) {
      c.mutex.Lock()
      c.sum++
      c.mutex.Unlock()
      wg.Done()
  }
  
  func main() {
      t := time.Now()
      c := new(calculation)
      wg := new(sync.WaitGroup)
      for i:=0; i&lt;10000000; i++{
          wg.Add(1)
          go dosomething(c, wg)
      }
      wg.Wait()
      fmt.Println(c.sum)
      fmt.Println(time.Since(t))
  }
  </code></pre>
  <p>But I found that use a mutex pointer works too:</p>
  <pre><code>type calculation struct{
      sum int
      mutex *sync.Mutex
  }
  
  func dosomething(c *calculation , wg *sync.WaitGroup) {
      c.mutex.Lock()
      c.sum++
      c.mutex.Unlock()
      wg.Done()
  }
  
  func main() {
      t := time.Now()
      c := &amp;calculation{0, new(sync.Mutex)}
      wg := new(sync.WaitGroup)
      for i:=0; i&lt;10000000; i++{
          wg.Add(1)
          go dosomething(c, wg)
      }
      wg.Wait()
      fmt.Println(c.sum)
      fmt.Println(time.Since(t))
  }
  </code></pre>
  <p>I made some tests on these 2 versions and found that there elapsed times are close.</p>
  <p>So which one should I use? And Why should I use a mutex or mutex pointer? Are they have performance differences?</p>