Re: [PATCH] Futexes IV (Fast Lightweight Userspace Semaphores)

Linus Torvalds
2002-03-09T01:20:55Z

On Fri, 8 Mar 2002, george anzinger wrote:
>
> Uh, just the pid would do. Maybe reserve a bit to indicate
> contention, but surly one word would be enough.

Not really.

The pid would mean that anybody who gets a lock would have to have its pid
available (remember the fast-path is what we really care about), but
there's also a fundamental race between getting the lock and writing the
pid to the second word of the lock that you just won't avoid.

And that's assuming you only use the semaphores for pure mutual exclusion.
That is the normal behaviour, but some people use semaphores for other
things (ie "N people can be active inside this region" where N != 1).

And then you have to realize that doing the same for readers in a rwlock
is even worse.

In short, it just cannot be done quickly and simply, and for many cases it
cannot be done at all.

Linus