title: Lock a mutex multiple times in the same thread
body: <p>I'm developing an application on an embedded linux OS (uClinux) and I need to be able to lock the mutex more than once (by the same thread).</p>
  <p>I have a mutex and a mutexattr defined and initialized as follows:</p>
  <pre><code>pthread_mutexattr_t waiting_barcode_mutexattr;
  pthread_mutex_t waiting_barcode_mutex;
  
  pthread_mutexattr_init(&amp;waiting_barcode_mutexattr);
  pthread_mutexattr_settype(&amp;waiting_barcode_mutexattr, PTHREAD_MUTEX_RECURSIVE);
  pthread_mutex_init(&amp;waiting_barcode_mutex, &amp;waiting_barcode_mutexattr);
  </code></pre>
  <p>But when I try to acquire the lock twice it blocks on the second lock:</p>
  <pre><code>pthread_mutex_lock(&amp;waiting_barcode_mutex);
  pthread_mutex_lock(&amp;waiting_barcode_mutex);
  </code></pre>
  <p>Am I initializing it wrong or is there a better way of accomplishing the same?</p>
  <p>Thanks in advance.</p>
  <h3>Conclusions:</h3>
  <ul>
  <li>Apparently PTHREAD_MUTEX_RECURSIVE or PTHREAD_MUTEX_RECURSIVE_NP don't work so I can't create a reentrant mutex.</li>
  <li>try_lock is no good either. It acquires the lock if it can and returns an error if it can't acquire the lock. Unfortunately the error just informs me that the mutex is already in use and I can´t find out if the current thread already owns the lock or not.</li>
  <li>pthread_mutex_lock can return an error if the current thread has the lock but for that I need to create a mutex of the type PTHREAD_MUTEX_ERRORCHECK, and I can't create one either.</li>
  </ul>