title: How to allow certain threads to have priority in locking a mutex use PTHREADS
body: <p>Assume that the following code is being executed by 10 threads.</p>
  
  <pre><code>pthread_mutex_lock(&amp;lock)
  Some trivial code
  pthread_mutex_unlock(&amp;lock)
  </code></pre>
  
  <p>For purpose of explanations lets say the threads are T1, T2, T3.....T10.
  My requirement is that as long as T1 or T2 or T3( i.e any of T1, T2 or T3) is waiting for acquiring a lock, the other threads i.t T4, T5, T6.....T10 should not be able to acquire the lock i.e T1, T2 and T3 should have precedence in acquiring the lock with respect to other threads.</p>
  
  <p>I guess it could be done by increasing the priority of threads T1, T2 and T3</p>
  
  <p>i.e here is the pseudo code</p>
  
  <pre><code>if this thread is T1 or T2 or T3
  increase its priority 
  pthread_mutex_lock(&amp;lock)
  Some trivial code
  pthread_mutex_unlock(&amp;lock)
  if this thread is T1 or T2 or T3 decrease it priority to normal
  </code></pre>
  
  <p><strong>Please note that I want a solution that is works for Linux platform and should use pthreads. I don't really care about any other platform.</strong></p>
  
  <p>Also note that I don't really want to make these 3 threads as realtime, I want them to exhibit their defualt behaviour(scheduling and priority) except that in the above mentioned small piece of code I want them to always have precedence in acquiring lock.</p>
  
  <p>I have read some man pages about scheduling policies and scheduling priorities in Linux but can't really make out :(</p>
  
  <p>Will this work? Can you help me with the exact pthread API required to accomplish the above task?</p>
  
  <p>Regards
  lali</p>