title: class member mutex assertion failed
body: <p>I'm trying to implement what I think is a fairly simple design.  I have a bunch of objects, each containing a std::map and there will be multiple processes accessing them.  I want to make sure that there is only one insert/erase to each of these maps at a time.  </p>
  
  <p>So I've been reading about boost::thread and class member mutexes and using bind to pass to class member which are all new things to me.  I started with a simple example from <a href="http://drdobbs.com/cpp/184401518" rel="nofollow">a Dr. Dobbs article</a> and tried modifying that.  I was getting all kinds of compiler errors due to my Threaded object having to be noncopyable.  After reading up on that, I decided I can avoid the hassle by keeping a pointer to a mutex instead.  So now I have code that compiles but results in the following error:</p>
  
  <pre><code>/usr/include/boost/shared_ptr.hpp:419:
      T* boost::shared_ptr&lt; &lt;template-parameter-1-1&gt; &gt;::operator-&gt;() const
      [with T = boost::mutex]: Assertion `px != 0' failed.  Abort
  </code></pre>
  
  <p>Now I'm really stuck and would really appreciate help with the code as well as comments on where I'm going wrong conceptually.  I realize there are some answered questions around these issues here already but I guess I'm still missing something.  </p>
  
  <pre><code>#include &lt;boost/thread/thread.hpp&gt;
  #include &lt;boost/thread/mutex.hpp&gt;
  #include &lt;boost/bind.hpp&gt;
  #include &lt;boost/shared_ptr.hpp&gt;
  #include &lt;iostream&gt;
  #include &lt;map&gt;
  
  using namespace std;
  
  class Threaded {
  public:
    std::map&lt;int,int&gt; _tsMap;
  
    void count(int id) {
      for (int i = 0; i &lt; 100; ++i) {
        _mx-&gt;lock();
        //std::cout &lt;&lt; id &lt;&lt; ": " &lt;&lt; i &lt;&lt; std::endl;      
        _tsMap[i] ++;
        _mx-&gt;unlock();
      }
    }
  
  private:
    boost::shared_ptr&lt;boost::mutex&gt; _mx;
  };
  
  
  int main(int argc, char* argv[]) {
    Threaded th;
    int i = 1;
    boost::thread thrd1(boost::bind(&amp;Threaded::count, &amp;th, 1));
    //boost::thread thrd2(boost::bind(&amp;th.count, 2));
    thrd1.join();
    //thrd2.join();
  
    return 0;
  }
  </code></pre>