On Tue, Mar 12, 2013 at 06:18:02PM +0530, Prabhu nath wrote:
I guess we should not mix mutex and condition variable. Both have their own respective semantics. *mutex* is used to serialize access to a shared resource among competing threads. *condition variable* is used to notify a* state change* of a resource to the interested thread.
In case of condition variable there is provision to explicitly notify a single thread(pthread_cond_signal) or all the threads waiting on a condition (or a state change) (pthread_cond_broadcast)
Question was on pthread_mutex_unlock() that whether this function invocation will trigger the movement of all the threads in the wait queue to the ready queue.
After pthread_mutex_unlock() is called , the mutex is release , then ,which stuff will reshcedule the threads in the waitqueue ? If do pthread_cond_signal() after each pthread_mutex_unlock() ,does it raise up the performence ? thanks!
If all the threads are of equal priority, then the first thread waiting for the lock will be put to READY queue. If there are variable priority threads waiting for the lock, then the thread with highest priority would be woken up