pthread_lock

Prabhu nath gprabhunath at gmail.com
Wed Mar 13 01:20:31 EDT 2013


On Wed, Mar 13, 2013 at 9:40 AM, ishare <june.tune.sea at gmail.com> wrote:

> 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!
>
I think you are missing something in your understanding. Please refer
"Programming with POSIX threads" - David R. Butenhof



>
>
>
>
>
> > 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
>
>
>
>


-- 
Regards,
Prabhunath G
Linux Trainer
Bangalore
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130313/05d6bda1/attachment.html 


More information about the Kernelnewbies mailing list