Skip to content

Commit 937d13b

Browse files
committed
relax a memory order in once_box
1 parent f79fae3 commit 937d13b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

library/std/src/sys/sync/once_box.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use crate::mem::replace;
99
use crate::ptr::null_mut;
1010
use crate::sync::atomic::AtomicPtr;
11-
use crate::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed};
11+
use crate::sync::atomic::Ordering::{Acquire, Relaxed, Release};
1212

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

0 commit comments

Comments
 (0)