* Does anyone know when FUTEX_WAIT can fail with EAGAIN?
@ 2014-07-29 21:55 Steven Stewart-Gallus
2014-08-16 21:51 ` Eric Wong
[not found] ` <fb82d1d46d8f.53d8186c-BTv7Ps/Sm75C8prJL3GQQw@public.gmane.org>
0 siblings, 2 replies; 3+ messages in thread
From: Steven Stewart-Gallus @ 2014-07-29 21:55 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-api, mtk
Hello,
I'm trying to debug a hangup where my program loops with FUTEX_WAIT (actually
FUTEX_WAIT_PRIVATE but same thing) endlessly erring out with EAGAIN. I would
like to know if anyone on the mailing list knows when FUTEX_WAIT can fail with
EAGAIN.
Some info for people who are interested in what I'm working on.
I'm working on sand boxing my program at gitorious.org/linted with namespaces
and chroot.
The error only appeared after changing unshare then fork code into a direct
clone call.
> | uname -a
> Linux alonzo 3.13.0-24-generic #1trisquel1 SMP Tue May 13 15:17:50 UTC 2014
x86_64 x86_64 x86_64 GNU/Linux
Thank you,
Steven Stewart-Gallus
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Does anyone know when FUTEX_WAIT can fail with EAGAIN?
2014-07-29 21:55 Does anyone know when FUTEX_WAIT can fail with EAGAIN? Steven Stewart-Gallus
@ 2014-08-16 21:51 ` Eric Wong
[not found] ` <fb82d1d46d8f.53d8186c-BTv7Ps/Sm75C8prJL3GQQw@public.gmane.org>
1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2014-08-16 21:51 UTC (permalink / raw)
To: Steven Stewart-Gallus; +Cc: linux-kernel, linux-api, mtk
Steven Stewart-Gallus <sstewartgallus00@mylangara.bc.ca> wrote:
> I'm trying to debug a hangup where my program loops with FUTEX_WAIT (actually
> FUTEX_WAIT_PRIVATE but same thing) endlessly erring out with EAGAIN. I would
> like to know if anyone on the mailing list knows when FUTEX_WAIT can fail with
> EAGAIN.
FUTEX_WAIT fails with EAGAIN if the value of *uaddr no longer matches
the expected val.
---
#include <linux/futex.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <errno.h>
int main(void) {
int op = FUTEX_WAIT;
int exp = 1;
int *addr = &exp;
int val = 1; /* XXX change this to anything else to get EAGAIN */
int rc = syscall(SYS_futex, addr, op, val, 0, 0, 0);
if (rc < 0 && errno == EAGAIN)
write(1, "EAGAIN\n", 7);
return 0;
}
---
I just encountered this myself yesterday while implementing futex-based
locks/condvars for Ruby:
https://bugs.ruby-lang.org/issues/10009#change-48372
^ permalink raw reply [flat|nested] 3+ messages in thread[parent not found: <fb82d1d46d8f.53d8186c-BTv7Ps/Sm75C8prJL3GQQw@public.gmane.org>]
* Re: Does anyone know when FUTEX_WAIT can fail with EAGAIN?
[not found] ` <fb82d1d46d8f.53d8186c-BTv7Ps/Sm75C8prJL3GQQw@public.gmane.org>
@ 2014-08-17 15:48 ` Davidlohr Bueso
0 siblings, 0 replies; 3+ messages in thread
From: Davidlohr Bueso @ 2014-08-17 15:48 UTC (permalink / raw)
To: Steven Stewart-Gallus
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-api-u79uwXL29TY76Z2rM5mHXA, mtk-ASgREoAs3yw,
davidlohr-VXdhtT5mjnY
On Tue, 2014-07-29 at 21:55 +0000, Steven Stewart-Gallus wrote:
> Hello,
>
> I'm trying to debug a hangup where my program loops with FUTEX_WAIT (actually
> FUTEX_WAIT_PRIVATE but same thing) endlessly erring out with EAGAIN. I would
> like to know if anyone on the mailing list knows when FUTEX_WAIT can fail with
> EAGAIN.
You're probably running into the EWOULDBLOCK return -- which on Linux is
just another name for EAGAIN. So if you didn't know this, and were
reading the code related to FUTEX_WAIT, you'd get mislead by this.
The check is there to avoid userspace misusing futexes and screwing up
applications. When the futex_wait() call is issued, a lot can happen in
the kernel before the task is blocked (key hashing, reference counting,
acquire internal spinlock, etc.). At any point while preparing to block,
another userspace thread could have changed the futex value, and thus
the condition for which futex_wait() call was issued in the first place
might no longer be true.
Thanks,
Davidlohr
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-08-17 15:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-29 21:55 Does anyone know when FUTEX_WAIT can fail with EAGAIN? Steven Stewart-Gallus
2014-08-16 21:51 ` Eric Wong
[not found] ` <fb82d1d46d8f.53d8186c-BTv7Ps/Sm75C8prJL3GQQw@public.gmane.org>
2014-08-17 15:48 ` Davidlohr Bueso
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox