@@ -464,6 +464,23 @@ impl AtomicBool {
464
464
/// **Note:** This method is only available on platforms that support atomic
465
465
/// operations on `u8`.
466
466
///
467
+ /// # Migrating to `compare_exchange` and `compare_exchange_weak`
468
+ ///
469
+ /// `compare_and_swap` is equivalent to `compare_exchange` with the following mapping for
470
+ /// memory orderings:
471
+ ///
472
+ /// Original | Success | Failure
473
+ /// -------- | ------- | -------
474
+ /// Relaxed | Relaxed | Relaxed
475
+ /// Acquire | Acquire | Acquire
476
+ /// Release | Release | Relaxed
477
+ /// AcqRel | AcqRel | Acquire
478
+ /// SeqCst | SeqCst | SeqCst
479
+ ///
480
+ /// `compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds,
481
+ /// which allows the compiler to generate better assembly code when the compare and swap
482
+ /// is used in a loop.
483
+ ///
467
484
/// # Examples
468
485
///
469
486
/// ```
@@ -1070,6 +1087,23 @@ impl<T> AtomicPtr<T> {
1070
1087
/// **Note:** This method is only available on platforms that support atomic
1071
1088
/// operations on pointers.
1072
1089
///
1090
+ /// # Migrating to `compare_exchange` and `compare_exchange_weak`
1091
+ ///
1092
+ /// `compare_and_swap` is equivalent to `compare_exchange` with the following mapping for
1093
+ /// memory orderings:
1094
+ ///
1095
+ /// Original | Success | Failure
1096
+ /// -------- | ------- | -------
1097
+ /// Relaxed | Relaxed | Relaxed
1098
+ /// Acquire | Acquire | Acquire
1099
+ /// Release | Release | Relaxed
1100
+ /// AcqRel | AcqRel | Acquire
1101
+ /// SeqCst | SeqCst | SeqCst
1102
+ ///
1103
+ /// `compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds,
1104
+ /// which allows the compiler to generate better assembly code when the compare and swap
1105
+ /// is used in a loop.
1106
+ ///
1073
1107
/// # Examples
1074
1108
///
1075
1109
/// ```
@@ -1612,6 +1646,23 @@ happens, and using [`Release`] makes the load part [`Relaxed`].
1612
1646
**Note**: This method is only available on platforms that support atomic
1613
1647
operations on [`" , $s_int_type, "`](" , $int_ref, ").
1614
1648
1649
+ # Migrating to `compare_exchange` and `compare_exchange_weak`
1650
+
1651
+ `compare_and_swap` is equivalent to `compare_exchange` with the following mapping for
1652
+ memory orderings:
1653
+
1654
+ Original | Success | Failure
1655
+ -------- | ------- | -------
1656
+ Relaxed | Relaxed | Relaxed
1657
+ Acquire | Acquire | Acquire
1658
+ Release | Release | Relaxed
1659
+ AcqRel | AcqRel | Acquire
1660
+ SeqCst | SeqCst | SeqCst
1661
+
1662
+ `compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds,
1663
+ which allows the compiler to generate better assembly code when the compare and swap
1664
+ is used in a loop.
1665
+
1615
1666
# Examples
1616
1667
1617
1668
```
0 commit comments