title: Multiple mutexes in same struct?
body: <p>I have a few related questions about Go's <code>sync.Mutex</code> used with <code>struct</code>. If I  were to, for instance, have this <code>struct</code>:</p>
  
  <pre><code>type something struct {
      aMux sync.Mutex
      a    map[string]interface{}
  
      bMux sync.Mutex
      b    int
  }
  </code></pre>
  
  <p>... <strong>would it be safe to lock <code>bMux</code> and access <code>b</code> while concurrently locking <code>aMux</code> and accessing <code>a</code> without a race condition?</strong></p>
  
  <p>It's probably also helpful to know that I'm accessing pointers to the structs, and using methods like this to lock/unlock the mutexes concurrently:</p>
  
  <pre><code>func (s *something) addA(k string, v interface{}) {
      (*s).aMux.Lock()
      (*s).a[k] = v
      (*s).aMux.Unlock()
  }
  
  func (s *something) addB(k string, v interface{}) {
      (*s).bMux.Lock()
      (*s).b++
      (*s).bMux.Unlock()
  }
  </code></pre>
  
  <p>My assumption is that this should theoretically be safe, since you can already lock a mutex in a struct without having to access the field(s) it locks. <strong>But when dereferencing a <code>struct</code> like above, does Go copy all the values from the <code>struct</code> (making it unsafe), or does it only modify/retrieve the fields you specify?</strong></p>
  
  <p>I would very much like to keep the mutexes in the same struct, since in my code I have multiple (up to six) related fields in the same struct that I lock separately with mutexes. <strong>If having multiple mutexes in the same struct (for related fields) is safe, but not recommended or bad practice, why? What would be a better structure?</strong></p>