title: When do you embed mutex in struct in Go?
body: <p>NOTE: I found the word 'embed' in the title was bad choice, but I will keep it. </p>
  
  <p>I see a lot of code does like this:</p>
  
  <pre><code>type A struct {
      mu sync.Mutex
      ...
  }
  </code></pre>
  
  <p>And use it like this:</p>
  
  <pre><code>a := &amp;A{}
  
  a.mu.Lock()
  defer a.mu.Unlock()
  
  a.Something()
  </code></pre>
  
  <p>Is it better than local mutex or global mutex?</p>
  
  <pre><code>a := &amp;A{}
  
  var mu sync.Mutex
  mu.Lock()
  defer mu.Unlock()
  
  a.Something()
  </code></pre>
  
  <p>When should I use former, or later?</p>