title: PTHREAD_MUTEX_RECURSIVE blocks on second thread
body: <p>I have the following problem with the PTHREAD_MUTEX_RECURSIVE: it blocks when the mutex is locked from another thread; </p>
  
  <pre><code>pthread_mutex_t m;
  pthread_mutexattr_t ma;
  
  void* exec_th(void* arg) {
      printf("THREAD %p before LOCK\n", pthread_self());
  
      //second mutex lock
      pthread_mutex_lock(&amp;m);
      printf("THREAD %p after LOCK\n", pthread_self());
  
      pthread_mutex_unlock(&amp;m);
      printf("THREAD %p after UNLOCK\n", pthread_self());
  
      return (void*)0;
  }
  
  int main() {
      pthread_mutexattr_init(&amp;ma);
      pthread_mutexattr_settype(&amp;ma, PTHREAD_MUTEX_RECURSIVE);
      pthread_mutex_init(&amp;m, &amp;ma);
  
      // first mutex lock
      pthread_mutex_lock(&amp;m);
  
      // create a thread that will call the same mutex
      pthread_t t;
      pthread_create(&amp;t, NULL, exec_th, NULL);
  
      sleep(1); //just to see the console
  
      pthread_mutex_unlock(&amp;m);
  }
  </code></pre>
  
  <p>The OpenGroup states: </p>
  
  <blockquote>
    <p>A thread attempting to relock this mutex without first unlocking it
    will succeed in locking the mutex. The relocking deadlock which can
    occur with mutexes of type PTHREAD_MUTEX_NORMAL cannot occur with this
    type of mutex</p>
  </blockquote>
  
  <p>Still, the above code generates the same behaviour for PTHREAD_MUTEX_RECURSIVE and PTHREAD_MUTEX_NORMAL:</p>
  
  <ul>
  <li>only <em>before LOCK</em> is printed before the sleep() in main();  </li>
  <li>the thread locks the mutex after it is released by the main();</li>
  </ul>
  
  <p>Any help is greatly appreciated, thank you.</p>