Skip to content
Snippets Groups Projects
Commit 802748b6 authored by Derick Eddington's avatar Derick Eddington
Browse files

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.
parent 90af0198
No related branches found
No related tags found
No related merge requests found
......@@ -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()`.
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment