title: Why can't I lock a base class mutex from a derived class?
body: <p>I have a base class B() with a member variable <code>pthread_mutex_t m</code>. When I try to lock the mutex from the derived class I block forever. I opened up GDB and printed what <code>m</code> looks like and it seems like gibberish (uninstantiated) but I'm not sure.</p>
  
  <p>Base Class</p>
  
  <pre><code>class B
  {
      protected: //or public!
          pthread_mutex_t m;
  
      public:
          virtual void lock(); //wrapper for pthread_mutex_lock(&amp;m)
          virtual void unlock(); //wrapper
  };
  </code></pre>
  
  <p>Derived Class</p>
  
  <pre><code>class D : B
  {
      public:
          void foo();
  
      private:
          pthread_mutex_t derived_m;
  };
  </code></pre>
  
  <p>And this is the code I have which blocks indefinitely.</p>
  
  <pre><code>D::foo() {
      //for reference below, gdb prints were taken here.
  
      pthread_mutex_lock(&amp;m); //blocks forever
      pthread_mutex_lock(&amp;derived_m); //okay
      lock(); //blocks forever
  }
  </code></pre>
  
  <p>GDB print() for &amp;m</p>
  
  <pre><code>$1 = {__data = {__lock = -8656, __count = 32767, __owner = 4198302, 
      __nusers = 0, __kind = 3, __spins = 0, __elision = 0, __list = {
        __prev = 0x400fed &lt;__libc_csu_init+77&gt;, __next = 0x0}}, 
    __size = "0\336\377\377\377\177\000\000\236\017@\000\000\000\000\000\003\000\000\000\000\000\000\000\355\017@", '\000' &lt;repeats 12 times&gt;, __align = 140737488346672}
  </code></pre>
  
  <p>GDB print() for &amp;derived_m</p>
  
  <pre><code>$2 = {__data = {__lock = 0, __count = 0, __owner = -134225560, 
      __nusers = 32767, __kind = 14, __spins = 0, __elision = 0, 
      __list = {__prev = 0x400e7f &lt;Logging::Logging(datastruct*)+67&gt;, 
        __next = 0x7fffffffddc0}}, 
    __size = "\000\000\000\000\000\000\000\000h\341\377\367\377\177\000\000\016\000\000\000\000\000\000\000\177\016@\000\000\000\000\000\300\335\377\377\377\177\000", __align = 0}
  </code></pre>