@@ -142,6 +142,7 @@ static void futex_wait(int32_t *futex)
return;
}
+wait:
while ((ret = futex_async(futex, FUTEX_WAIT, -1, NULL, NULL, 0))) {
err = errno;
fprintf(stderr, "%lu: wq %p: %s failed, errno %d\n",
@@ -161,7 +162,16 @@ static void futex_wait(int32_t *futex)
fprintf(stderr, "%lu: wq %p: %s wait return %d\n",
pthread_self(), caa_container_of(futex, struct urcu_workqueue, futex), __func__, ret);
-
+ /*
+ * Prior queued wakeups can cause futex wait to return even
+ * though the futex value is still -1. If this happens, wait
+ * again.
+ */
+ if (uatomic_read(futex) == -1) {
+ fprintf(stderr, "%lu: wq %p: %s futex == -1, wait again\n",
+ pthread_self(), caa_container_of(futex, struct urcu_workqueue, futex), __func__);
+ goto wait;
+ }
}
static void futex_wake_up(int32_t *futex)