Date: Fri, 04 Mar 2005 09:50:45 -0700 From: Scott Long <scottl@samsco.org> To: Colin Percival <cperciva@freebsd.org> Cc: David Xu <davidxu@freebsd.org> Subject: Re: cvs commit: src/sys/kern kern_sig.c Message-ID: <422891E5.3040402@samsco.org> In-Reply-To: <42288FA6.7010102@freebsd.org> References: <Pine.GSO.4.43.0503031020180.2058-100000@sea.ntplx.net> <200503031116.22840.jhb@FreeBSD.org> <20050305032619.K18638@delplex.bde.org> <42288FA6.7010102@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?422891E5.3040402>