[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

RE: Thread starvation with mutex



[trimmed the CC list]

> From: Jamie Lokier [mailto:jamie shareable org]
> Perez-Gonzalez, Inaky wrote:
> > > Note that Rusty's futex library does offer both.  The kernel's futuex
> > > primitive is capable of strict ownership transferral in FIFO order.
> > >
> > > Sometimes you want immediate ownership transferral, but in a more
> > > efficient "fair" but not FIFO, or RT (which is not always fair) order.
> >
> > Hmmm...how? Are you referring as in waking the waiter without
> > unlocking the futex in user space?
> > I don't really see it very clear, I am kind of very thick now -- please
> > be patient with me---I've slept three hours only
> 
> FUTEX_WAKE returns a value indicating the number of threads actually
> woken.  So the first thread calls FUTEX_WAKE with parameter 1: if that
> returns 0, it unlocks the userspace word, otherwise it leaves the
> userspace word unchanged.

I see -- I tried this, and unless I missed something, there is
a problem:

1. Thread A calls FUTEX_WAKE
2. Thread A receives 0 from FUTEX_WAKE
3. Thread A atomically unlocks the user space word

Now, if some Thread B comes in between 2 and 3 and tries to
lock, it will see the user space word locked and go down to
wait in the kernel. It will sit there for ever because 
in (3) the word is locked and nobody knows B is there sleeping.

This can happen on an SMP system or on a UP (with normal
preemption).

[btw, this is the main reason why rtfutex and fusyn do the 
manipulation of the userspace word in the kernel for the slow
path, because the actual poking in the futex/fulock and the 
manipulation of the userspace data have to be atomic].

> > Did you give me that feedback before or did I just miss it? It is
> > _very_ simple to add that functionality (in fact, it is a one or
> > two liner). I had never really thought of adding it because nobody
> > asked for it (or because I never realized somebody did).
> 
> I have mentioned it before on phil-list.  Ulrich said he understood
> but it wasn't useful for NPTL.  And it _has_ been in Rusty's original
> futex-2.2 library, which predates NPTL (I would never have thought of
> it without Rusty's code - matching the numbers in the kernel is clever).

[confused] Are you talking about the FIFO unlock order or the strict
ownership transferal? (I was talking about the FIFO).

Thanks!

Iñaky Pérez-González -- Not speaking for Intel -- all opinions are my own (and my fault)




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]