From: june.tune.sea@gmail.com (ishare) Date: Wed, 13 Mar 2013 12:10:48 +0800 Subject: pthread_lock In-Reply-To: References: <20130305044402.GA3117@debian.localdomain> <21589.1362463371@turing-police.cc.vt.edu> <20130305100546.GA2541@debian.localdomain> Message-ID: <20130313041048.GA2519@debian.localdomain> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org 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