From 09e456c2d0a386af5bf01b9cfb38d6b2fc2c6aa8 Mon Sep 17 00:00:00 2001 From: Ponnuvel Palaniyappan Date: Wed, 8 Jan 2020 09:09:48 +0000 Subject: [PATCH] futex.2: Fix a bug in the example The man page contains a trivial bug that's discussed here: https://stackoverflow.com/q/59628958 Signed-off-by: Michael Kerrisk --- man2/futex.2 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/man2/futex.2 b/man2/futex.2 index 8a003e2be..01b36cac3 100644 --- a/man2/futex.2 +++ b/man2/futex.2 @@ -1797,8 +1797,8 @@ fwait(int *futexp) while (1) { /* Is the futex available? */ - const int zero = 0; - if (atomic_compare_exchange_strong(futexp, &zero, 1)) + const int one = 1; + if (atomic_compare_exchange_strong(futexp, &one, 0)) break; /* Yes */ /* Futex is not available; wait */ @@ -1820,8 +1820,8 @@ fpost(int *futexp) /* atomic_compare_exchange_strong() was described in comments above */ - const int one = 1; - if (atomic_compare_exchange_strong(futexp, &one, 0)) { + const int zero = 0; + if (atomic_compare_exchange_strong(futexp, &zero, 1)) { s = futex(futexp, FUTEX_WAKE, 1, NULL, NULL, 0); if (s == \-1) errExit("futex\-FUTEX_WAKE");