I guess we should not mix mutex and condition variable. Both have their own respective semantics. <br><i>mutex</i> is used to serialize access to a shared resource among competing threads.<br><i>condition variable</i> is used to notify a<i> state change</i> of a resource to the interested thread. <br>
<br>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)<br><br>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. <br>
If all the threads are of equal priority, then the first thread waiting for the lock will be put to READY queue. <br>If there are variable priority threads waiting for the lock, then the thread with highest priority would be woken up <br>
<br clear="all"><div>Regards,<br>Prabhunath G<br>Linux Trainer<br>Bangalore<br></div>
<br><br><div class="gmail_quote">On Tue, Mar 5, 2013 at 3:35 PM, ishare <span dir="ltr"><<a href="mailto:june.tune.sea@gmail.com" target="_blank">june.tune.sea@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On Tue, Mar 05, 2013 at 01:39:54PM +0530, Mandeep Sandhu wrote:<br>
> On Tue, Mar 5, 2013 at 11:32 AM, <<a href="mailto:Valdis.Kletnieks@vt.edu" target="_blank">Valdis.Kletnieks@vt.edu</a>> wrote:<br>
> > On Tue, 05 Mar 2013 11:02:45 +0530, Mandeep Sandhu said:<br>
> ><br>
> >> next schedule. I think the waiting threads (processes) will moved from<br>
> >> the wait queue to the run queue from where they will be scheduled to<br>
> >> run.<br>
> ><br>
> > For bonus points, read source code and/or comments and figure out what<br>
> > Linux does to prevent the 'thundering herd' problem (consider 100 threads<br>
> > all waiting on the same mutex - if you blindly wake all 100 up, you'll schedule<br>
> > them all, the first will find the mutex available and then re-take it, and<br>
> > then the next 99 will get run only to find it contended and go back to<br>
> > sleep. So figure out what Linux does in that case. :)<br>
><br>
> Googling around, I found the 'thundering herd' being mentioned in<br>
> relation to threads waiting on sockets using the accept() sys call.<br>
> Are wait's on mutex's also plagued by the same issue? I guess it is,<br>
> though what sys call would be used in this case?<br>
<br>
</div> the threads waiting on sockets will be waked up by net event.<br>
similarly,the waiters on mutex's can be wake up by signal.I guess it is pthread_cont_signal<br>
<div><div><br>
<br>
><br>
> Thanks,<br>
> -mandeep<br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</div></div></blockquote></div><br>