[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: compat linux futex locking problem
On Mon, Jun 02, 2008 at 10:07:55AM +0200, Nicolas Joly wrote:
> While testing some threaded apps under amd64 NTPL linux emulation, i
> discovered a locking problem with our futex implementation.
> In most cases, futex_get() is called from linux_sys_futex() without
> lock held, but there is one extra call in futex_wake() where the futex
> lock is already hold ... leading to a panic.
> I'm not sure about the correct way to fix it (i'm not a locking
> specialist) and wanted to ask.
> In the mean time, i checked the corresponding code in FreeBSD which
> added an extra argument to futex_get to record if the lock is already
> hold. But that does not seems right to me, especially because
> futex_get() can sleep for quite some time due to a call to
> kmem_zalloc(x, KM_SLEEP).
> Any hint/advice ?
I think easiest way is to require that futex_get/put/wake/wait are always
called holding futex_lock.
The KM_SLEEP I'm not sure about. The lazy option is to hold futex_lock
across the call; if the lock is not held then the operation needs to
re-check conditions after releasing the lock.
I'm not sure how futexes work, but is it possible that there is a race
in that code? Presumably a FUTEX_WAKE can arrive before the thread that
we want to wake has called into the kernel and done FUTEX_WAIT?
Main Index |
Thread Index |