3

When i call 'pthread_cond_signal' during my thread's function, does this call unlock the mutex i currently use? (Not the one the pthread_cond_wait is waiting for).

Zach
  • 537
  • 4
  • 9
  • 19

2 Answers2

5

Only the mutex given to pthread_cond_(timed_)wait() is unlocked to give other threads the chance to change the condition. At the end of pthread_cond_wait, the mutex is locked again. No other functions lock/unlock mutexes.

stefaanv
  • 14,072
  • 2
  • 31
  • 53
3

No, it doesn't unlock any mutex at all. pthread_cond_wait does unlock its mutex, and when it exits the mutex is locked again.

Mark B
  • 95,107
  • 10
  • 109
  • 188
  • I'm pretty sure from my reading that both answers are saying about the same thing just in slightly different ways. – Mark B Dec 03 '19 at 19:47