From a87fb1802761ee51b2f9f8928e50c27c6b64ab9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAnior=20Bassani?= Date: Tue, 6 Jul 2021 10:50:17 -0300 Subject: [PATCH 1/2] Replace deprecated compare_and_swap by compare_exchange_weak in core::sync::atomic::fence example --- library/core/src/sync/atomic.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index f1a115563fd3e..3f5c10b02eb70 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -2648,7 +2648,11 @@ unsafe fn atomic_umin(dst: *mut T, val: T, order: Ordering) -> T { /// /// pub fn lock(&self) { /// // Wait until the old value is `false`. -/// while self.flag.compare_and_swap(false, true, Ordering::Relaxed) != false {} +/// while self +/// .flag +/// .compare_exchange_weak(false, true, Ordering::Relaxed, Ordering::Relaxed) +/// .is_err() +/// {} /// // This fence synchronizes-with store in `unlock`. /// fence(Ordering::Acquire); /// } From 0d61e6e8d68be269c57d1d067f29a8a0e5eb6e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAnior=20Bassani?= Date: Tue, 6 Jul 2021 10:53:14 -0300 Subject: [PATCH 2/2] Fix typo in core::sync::atomic::compiler_fence example --- library/core/src/sync/atomic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index 3f5c10b02eb70..b673b36c10211 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -2714,7 +2714,7 @@ pub fn fence(order: Ordering) { /// Without `compiler_fence`, the `assert_eq!` in following code /// is *not* guaranteed to succeed, despite everything happening in a single thread. /// To see why, remember that the compiler is free to swap the stores to -/// `IMPORTANT_VARIABLE` and `IS_READ` since they are both +/// `IMPORTANT_VARIABLE` and `IS_READY` since they are both /// `Ordering::Relaxed`. If it does, and the signal handler is invoked right /// after `IS_READY` is updated, then the signal handler will see /// `IS_READY=1`, but `IMPORTANT_VARIABLE=0`.