Fix: compare loaded futex value after futex wait syscall return
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 24 Nov 2022 19:13:41 +0000 (14:13 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 24 Nov 2022 19:13:41 +0000 (14:13 -0500)
Handle spurious wakeups.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/rcu.c

index 1fd1af21a8e71757901ca3bfabb1c6e19f1cf8c8..9652725fdc1f037e9bf2eada107fdf954c489b90 100644 (file)
--- a/src/rcu.c
+++ b/src/rcu.c
@@ -89,9 +89,14 @@ void wait_gp(struct side_rcu_gp_state *gp_state)
        } else {
                __atomic_thread_fence(__ATOMIC_SEQ_CST);
        }
-       if (__atomic_load_n(&gp_state->futex, __ATOMIC_RELAXED) != -1)
-               return;
-       while (futex(&gp_state->futex, FUTEX_WAIT, -1, NULL, NULL, 0)) {
+       while (__atomic_load_n(&gp_state->futex, __ATOMIC_RELAXED) == -1) {
+               if (!futex(&gp_state->futex, FUTEX_WAIT, -1, NULL, NULL, 0)) {
+                       /*
+                        * May be awakened by either spurious wake up or
+                        * because the state is now as expected.
+                        */
+                       continue;
+               }
                switch (errno) {
                case EWOULDBLOCK:
                        /* Value already changed. */
This page took 0.024739 seconds and 4 git commands to generate.