Berkeley DB infinite sleep on Solaris [#3245]

Alex Kiernan alexk at demon.net
Tue Jan 9 13:12:08 UTC 2001


"David Schwartz" <davids at webmaster.com> writes:

> > The Solaris man page (_lwp_cond_signal) is explicit:
> >
> >     "Both functions should be called under the protection of  the
> >      same  LWP  mutex  lock  that  is used with the LWP condition
> >      variable being  signaled. Otherwise, the condition  variable
> >      may  be  signalled between the test of the associated condi-
> >      tion and blocking in _lwp_cond_wait().  This  can  cause  an
> >      infinite wait."
> 
> 	This is flat-out incorrect. What it's suggesting is that the following can
> happen:
> 
> Lock();
> while(!Test_Predicate())
> {
>  <-- signal can occur here and be lost
>  UnlockAndBlockThenRelock();
> }
> Act();
> Unlock();
> 

The problem is when the mutex is unlocked inside _lwp_cond_wait and
the then sleeps - there's no locking around this, so another thread
can get in lock the mutex, change the state of the condition variable,
unlock & signal before we go to sleep in cond_wait.

With pthread semantics I agree, it guarantees that you can hold or not
hold the mutex, with Solaris lwp this appears not to be true.

-- 
Alex Kiernan, Principal Engineer, Development, Thus PLC



More information about the inn-workers mailing list