Skip to content

Commit

Permalink
relax a memory order in once_box
Browse files Browse the repository at this point in the history
  • Loading branch information
slanterns committed Oct 15, 2024
1 parent 7d1457e commit e35d9fe
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions std/src/sys/sync/once_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use crate::mem::replace;
use crate::ptr::null_mut;
use crate::sync::atomic::AtomicPtr;
use crate::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed};
use crate::sync::atomic::Ordering::{Acquire, Relaxed, Release};

pub(crate) struct OnceBox<T> {
ptr: AtomicPtr<T>,
Expand Down Expand Up @@ -60,7 +60,7 @@ impl<T> OnceBox<T> {
#[cold]
fn initialize(&self, f: impl FnOnce() -> Box<T>) -> &T {
let new_ptr = Box::into_raw(f());
match self.ptr.compare_exchange(null_mut(), new_ptr, AcqRel, Acquire) {
match self.ptr.compare_exchange(null_mut(), new_ptr, Release, Acquire) {
Ok(_) => unsafe { &*new_ptr },
Err(ptr) => {
// Lost the race to another thread.
Expand Down

0 comments on commit e35d9fe

Please sign in to comment.