@@ -716,6 +716,12 @@ impl AtomicBool {
716716 /// AcqRel | AcqRel | Acquire
717717 /// SeqCst | SeqCst | SeqCst
718718 ///
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.
719725 /// `compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds,
720726 /// which allows the compiler to generate better assembly code when the compare and swap
721727 /// is used in a loop.
@@ -1651,6 +1657,12 @@ impl<T> AtomicPtr<T> {
16511657 /// AcqRel | AcqRel | Acquire
16521658 /// SeqCst | SeqCst | SeqCst
16531659 ///
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.
16541666 /// `compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds,
16551667 /// which allows the compiler to generate better assembly code when the compare and swap
16561668 /// is used in a loop.
@@ -2771,6 +2783,12 @@ macro_rules! atomic_int {
27712783 /// AcqRel | AcqRel | Acquire
27722784 /// SeqCst | SeqCst | SeqCst
27732785 ///
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.
27742792 /// `compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds,
27752793 /// which allows the compiler to generate better assembly code when the compare and swap
27762794 /// is used in a loop.
0 commit comments