wakeup idea...

Robert Watson rwatson at FreeBSD.org
Sun Mar 5 05:36:37 PST 2006


On Sun, 5 Mar 2006, Poul-Henning Kamp wrote:

> Here is a possibly stupid idea.
>
> Historically sleep/wakeup have happened on a pointer which was just a magic 
> number.
>
> In many cases, this pointer is actually a relevant datastructure.
>
> Would it possibly be an optimization to make a variant of the sleep/wakeup 
> calls where the pointer points to an integer type which contains non-zero if 
> anybody is actually sleeping on that address ?
>
> Anybody up for a quick prototype ?

In principle this is part of the point of a condition variable, which 
associates a struct with waitable conditions, and includes an int that 
contains the number of waiters:

struct cv {
         const char      *cv_description;
         int             cv_waiters;
};

Presumably the tricky bit is optimizing this such that you avoid undesirable 
races.  (But maybe if you call cv_signal without the condition mutex held, you 
accept that race by definition?)

Robert N M Watson


More information about the freebsd-arch mailing list