[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: nptl 0.26



dada1 wrote:

> There is no semantic difference between
> 
> ******** your version)
> 
> lll_lock()
> if (condition) {
>   ++sequence;
>   futex_wake(&sequence, 1);
>   }
> lll_unlock()
> 
> ****** The alternate version more lock friendly)
> 
> lll_lock()
> if (condition) {
>   ++sequence;
>   lll_unlock(); /* release the lock before the syscall */
>   futex_wake(&sequence, 1);
>   }
> else
>    lll_unlock();
> 

No, you are wrong.  As soon as the lock is released another thread can
come in and try to get the condvar.  It'll end up in the kernel, waiting
for the futex.  If it is this one thread which gets woken by the
cond_signal call (rmember: time gap between release and FUTEX_WAKE) the
thread will find that the condition

  if (cv->woken_seq >= seq && cv->woken_seq < val) {

is still wrong and it will go to sleep again.  Now no thread got woken.

-- 
--------------.                        ,-.            444 Castro Street
Ulrich Drepper \    ,-----------------'   \ Mountain View, CA 94041 USA
Red Hat         `--' drepper at redhat.com `---------------------------





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]