@@ -716,6 +716,12 @@ impl AtomicBool {
716
716
/// AcqRel | AcqRel | Acquire
717
717
/// SeqCst | SeqCst | SeqCst
718
718
///
719
+ /// `compare_and_swap` and `compare_exchange` also differ in their return type. You can use
720
+ /// `compare_exchange(...).unwrap_or_else(|x| x)` to recover the behavior of `compare_and_swap`,
721
+ /// but in most cases it is more idiomatic to check whether the return value is `Ok` or `Err`
722
+ /// rather than to infer success vs failure based on the value that was read.
723
+ ///
724
+ /// During migration, consider whether it makes sense to use `compare_exchange_weak` instead.
719
725
/// `compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds,
720
726
/// which allows the compiler to generate better assembly code when the compare and swap
721
727
/// is used in a loop.
@@ -1651,6 +1657,12 @@ impl<T> AtomicPtr<T> {
1651
1657
/// AcqRel | AcqRel | Acquire
1652
1658
/// SeqCst | SeqCst | SeqCst
1653
1659
///
1660
+ /// `compare_and_swap` and `compare_exchange` also differ in their return type. You can use
1661
+ /// `compare_exchange(...).unwrap_or_else(|x| x)` to recover the behavior of `compare_and_swap`,
1662
+ /// but in most cases it is more idiomatic to check whether the return value is `Ok` or `Err`
1663
+ /// rather than to infer success vs failure based on the value that was read.
1664
+ ///
1665
+ /// During migration, consider whether it makes sense to use `compare_exchange_weak` instead.
1654
1666
/// `compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds,
1655
1667
/// which allows the compiler to generate better assembly code when the compare and swap
1656
1668
/// is used in a loop.
@@ -2771,6 +2783,12 @@ macro_rules! atomic_int {
2771
2783
/// AcqRel | AcqRel | Acquire
2772
2784
/// SeqCst | SeqCst | SeqCst
2773
2785
///
2786
+ /// `compare_and_swap` and `compare_exchange` also differ in their return type. You can use
2787
+ /// `compare_exchange(...).unwrap_or_else(|x| x)` to recover the behavior of `compare_and_swap`,
2788
+ /// but in most cases it is more idiomatic to check whether the return value is `Ok` or `Err`
2789
+ /// rather than to infer success vs failure based on the value that was read.
2790
+ ///
2791
+ /// During migration, consider whether it makes sense to use `compare_exchange_weak` instead.
2774
2792
/// `compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds,
2775
2793
/// which allows the compiler to generate better assembly code when the compare and swap
2776
2794
/// is used in a loop.
0 commit comments