cvs commit: src/sys/kern kern_sig.c

Scott Long scottl at samsco.org
Fri Mar 4 16:53:13 GMT 2005


Colin Percival wrote:
> Bruce Evans wrote:
> 
>>Sleeping on a stack address is just a bug [...]
> 
> 
> I was told that this was the canonical way to say "go to sleep and don't
> wake up until the timo expires" was to tsleep() with ident equal to
> something from the stack.
> 
> If this isn't correct, what is the correct way to do this?  I've seen
> some code which does tsleep(NULL, ... ), but I was told that was also
> wrong.
> 
> Colin Percival

The first argument to tsleep/msleep is just a cookie that is supposed to
uniquely identify the sleeper for when you want to wake it up. Having
colliding cookies isn't terrible, but it means that the other colliding
sleepers might get woken up when they don't expect it.  Using NULL is no
different than using a cookie with a very high probability of collision.
The suggestion to use a stack address from the local frame was made
because it gives you a fairly good chance of obtaining a unique value.
However, as Bruce points out, it's really just a side effect of the MD
stack allocation scheme, and is no way a guarantee.  Using an address
from the global heap is probably a better choice, but since the stacks
are also allocated from the global heap now, there really isn't much of
a difference.

Scott


More information about the cvs-src mailing list