I don't see how we could use them either.  They are a solution
for a different problem.

                        Mark.

On Thu, 25 Sep 2003, Emmanuel Allaud wrote:

> /I did not have news from my request on linux-kernel, but I came across 
> this interview of Rusty Russel where he talks about futexes (URL : 
> http://kerneltrap.org/node/view/892) :
> /
> 
> /
> ---------
> /
> 
> /Rusty Russell/: OK, a futex ("Fast Userspace Mutex") isn't a mutex at 
> all. It was in a (much) earlier implemetation, but now it's just a 
> waitqueue primitive accessible to userspace. FUTEX_WAKE says "wake 
> anyone waiting on this address", and FUTEX_WAIT says "when I read ADDR, 
> it contained VALUE: if it still contains that value when you look at it, 
> sleep until someone calls FUTEX_WAKE on this address".
> 
> It's used as follows. Two processes (or threads) share some memory, and 
> agree to use a part of it as a lock. 1 means unlocked, 0 means locked, < 
> 0 means locked and someone is waiting. To grab the lock, you do an 
> (architecture-specific) atomic decrement operation: if it hits 0, then 
> it was 1, and you've got the lock. Otherwise you wait for a while. When 
> you want to release the lock, you set it to 1 again. This is really fast 
> if there's no contention on the lock: not a system call in sight.
> 
> Before futexes, the "wait a while" was usually implemented "try three 
> times and then call yield()". The problem with yield is that it has no 
> clear semantics: the kernel has *no* idea what you are waiting for, so 
> it has to guess when to wake you up. In a word, "yield()" is always a hack.
> 
> With futexes, you say "this address was -1 when I finished with it, 
> sleep on it": the kernel atomically checks the value and either puts you 
> to sleep or returns EAGAIN, and you try again. When you release a lock, 
> if it's 0, you can simply increment it back to 1, otherwise, you set it 
> to 1 and call FUTEX_WAKE, because you know someone is waiting. You can 
> read some example code here 
> <http://www.kernel.org/pub/linux/kernel/people/rusty/futex-2.2.tar.gz>, 
> and of course in the current glibc sources.
> 
> -------------------
> 
> The thing here is that I still don't know how we would use futexes...
> Bye
> Manu
> 
> 
> 

_______________________________________________
Devel mailing list
[EMAIL PROTECTED]
http://XFree86.Org/mailman/listinfo/devel

Reply via email to