title: Boost, Mutex, class member, shared object member
body: <p>I am new to multithread programming, please don't laugh if this seems too simple.</p>
  
  <p>I have a simple class object which has several member variables, e.g., </p>
  
  <pre><code>class XYZ
  {
  public:
  int a;
  int b;
  ...
  };
  </code></pre>
  
  <p>xyz is a shared objects among multiple threads, what's the best way to share "a" among multiple threads? For example,</p>
  
  <p>In thread A, I will do something like</p>
  
  <pre><code>xyz.a = xyz.a + rand();
  </code></pre>
  
  <p>In thread B, I will do something like</p>
  
  <pre><code>xyz.a = xyz.a - rand();
  </code></pre>
  
  <p>I heard about create a mutex as a class member, can someone please give a simple example how to do that.</p>
  
  <p>How can I create a class interface which allows multiple threads to safely access its member?</p>