title: Pthread Mutex: pthread_mutex_unlock() consumes lots of time
body: <p>I wrote a multi-thread program with pthread, using the producer-consumer model. </p>
  
  <p>When I use Intel VTune profiler to profile my program, I found the producer and consumer spend lots of time on pthread_mutex_unlock. I don't understand why this happened. I think threads may wait a long time before they can acquire a mutex, but releasing a mutex should be fast, right?</p>
  
  <p>The snapshot below is from Intel VTune. It shows the codes where consumer tries to fetch an item from the buffer, and time consumed by each code line.</p>
  
  <p>My question is that why pthread_mutex_unlock has such overhead? Is the problem with pthread mutex itself or with the way I use it?
  <img src="https://i.stack.imgur.com/c7WuP.png" alt="enter image description here"></p>