diff options
| author | Slanterns <slanterns.w@gmail.com> | 2024-10-16 00:22:05 +0800 |
|---|---|---|
| committer | Slanterns <slanterns.w@gmail.com> | 2024-10-16 00:42:23 +0800 |
| commit | 937d13b8efc43f3f2e93f81360565d82f243ce15 (patch) | |
| tree | 49e247b8623808ddcd35a051afb2f3c9ed428c49 | |
| parent | f79fae3069c449993eda6b16934da3b144cb8a66 (diff) | |
| download | rust-937d13b8efc43f3f2e93f81360565d82f243ce15.tar.gz rust-937d13b8efc43f3f2e93f81360565d82f243ce15.zip | |
relax a memory order in `once_box`
| -rw-r--r-- | library/std/src/sys/sync/once_box.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/library/std/src/sys/sync/once_box.rs b/library/std/src/sys/sync/once_box.rs index 1422b5a1721..9d24db2245a 100644 --- a/library/std/src/sys/sync/once_box.rs +++ b/library/std/src/sys/sync/once_box.rs @@ -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>, @@ -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. |
