Skip to content

Commit

Permalink
SeqCst->Relaxed in pal::windows::pipe.
Browse files Browse the repository at this point in the history
Relaxed is enough to ensure fetch_add(1) returns each integer exactly
once.
  • Loading branch information
m-ou-se committed Mar 19, 2024
1 parent 46bb073 commit 60ad490
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions library/std/src/sys/pal/windows/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::path::Path;
use crate::ptr;
use crate::slice;
use crate::sync::atomic::AtomicUsize;
use crate::sync::atomic::Ordering::SeqCst;
use crate::sync::atomic::Ordering::Relaxed;
use crate::sys::c;
use crate::sys::fs::{File, OpenOptions};
use crate::sys::handle::Handle;
Expand Down Expand Up @@ -214,11 +214,11 @@ pub fn spawn_pipe_relay(
fn random_number() -> usize {
static N: AtomicUsize = AtomicUsize::new(0);
loop {
if N.load(SeqCst) != 0 {
return N.fetch_add(1, SeqCst);
if N.load(Relaxed) != 0 {
return N.fetch_add(1, Relaxed);
}

N.store(hashmap_random_keys().0 as usize, SeqCst);
N.store(hashmap_random_keys().0 as usize, Relaxed);
}
}

Expand Down

0 comments on commit 60ad490

Please sign in to comment.