Rollup merge of #114359 - ttsugriy:barrier-simpl, r=cuviper
[library/std] Replace condv while loop with `cvar.wait_while`. `wait_while` takes care of spurious wake-ups in centralized place, reducing chances for mistakes and potential future optimizations (who knows, maybe in future there will be no spurious wake-ups? :)
This commit is contained in:
commit
5da7f36485
@ -130,11 +130,8 @@ pub fn wait(&self) -> BarrierWaitResult {
|
|||||||
let local_gen = lock.generation_id;
|
let local_gen = lock.generation_id;
|
||||||
lock.count += 1;
|
lock.count += 1;
|
||||||
if lock.count < self.num_threads {
|
if lock.count < self.num_threads {
|
||||||
// We need a while loop to guard against spurious wakeups.
|
let _guard =
|
||||||
// https://en.wikipedia.org/wiki/Spurious_wakeup
|
self.cvar.wait_while(lock, |state| local_gen == state.generation_id).unwrap();
|
||||||
while local_gen == lock.generation_id {
|
|
||||||
lock = self.cvar.wait(lock).unwrap();
|
|
||||||
}
|
|
||||||
BarrierWaitResult(false)
|
BarrierWaitResult(false)
|
||||||
} else {
|
} else {
|
||||||
lock.count = 0;
|
lock.count = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user