Fix Rwlock::acquire_write_lock to avoid blocking indefinitely.

Without this fix, `tests/bins_static/pthread/rwlock_randtest` would sometimes get stuck blocking
forever with only 1+ threads all doing `pthread_rwlock_wrlock()` but all the other threads
having finished.
This commit is contained in:
Derick Eddington
2024-07-06 01:13:23 -07:00
parent 90af01986c
commit 802748b611
+9 -1
View File
@@ -45,7 +45,15 @@ impl Rwlock {
};
waiting_wr = expected & WAITING_WR;
let _ = crate::sync::futex_wait(&self.state, expected, deadline);
if actual & COUNT_MASK > 0 {
let _ = crate::sync::futex_wait(&self.state, expected, deadline);
} else {
// We must avoid blocking indefinitely in our `futex_wait()`, in this case
// where it's possible that `self.state == expected` but our futex might
// never be woken again, because it's possible that all other threads
// already did their `futex_wake()` before we would've done our
// `futex_wait()`.
}
}
}
}