Thread (3 messages) 3 messages, 3 authors, 2014-08-17

Re: Does anyone know when FUTEX_WAIT can fail with EAGAIN?

flat view

From: Eric Wong <hidden>
Date: 2014-08-16 21:57:23
Also in: lkml

Steven Stewart-Gallus [off-list ref] 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help