title: Why is passing references to the Mutex class not a good design?
body: <p>From here: <a href="https://stackoverflow.com/questions/34544833/logic-error-in-my-defined-mutex-class-and-the-way-i-use-it-in-producer-consumer/34545100?noredirect=1#comment56832281_34544833">Logic error in my defined Mutex class and the way I use it in producer consumer program - pthreads</a></p>
  
  <blockquote>
    <p>the way you pass around references(!) to your mutex class is plainly asking for trouble, it defies any kind of encapsulation. </p>
  </blockquote>
  
  <p>Why is this a problem? Should I have passed by value and then written the copy constructor?</p>
  
  <p>What harms can lack of encapsulation do in this case? How should I encapsulate what? </p>
  
  <p>Also, <a href="https://stackoverflow.com/questions/34553232/why-is-passing-references-to-the-mutex-class-not-a-good-design#comment56849351_34553232">Why is passing references to the Mutex class not a good design?</a></p>
  
  <blockquote>
    <p>Passing a reference to the lock is a bad idea -- you don't "use" the lock, you only acquire and then you give it back. Moving it around makes it hard to track your use of the (critical) resource. Passing a reference to a mutex variable rather than a lock is maybe not so bad, but still it makes it harder to know what parts of the program may deadlock, so its something to avoid.</p>
  </blockquote>
  
  <p>Please explain in simple language with examples - why is passing references a bad idea?</p>