@@ -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
/// ```
@@ -1048,6 +1065,23 @@ impl<T> AtomicPtr<T> {
1048
1065
/// **Note:** This method is only available on platforms that support atomic
1049
1066
/// operations on pointers.
1050
1067
///
1068
+ /// # Migrating to `compare_exchange` and `compare_exchange_weak`
1069
+ ///
1070
+ /// `compare_and_swap` is equivalent to `compare_exchange` with the following mapping for
1071
+ /// memory orderings:
1072
+ ///
1073
+ /// Original | Success | Failure
1074
+ /// -------- | ------- | -------
1075
+ /// Relaxed | Relaxed | Relaxed
1076
+ /// Acquire | Acquire | Acquire
1077
+ /// Release | Release | Relaxed
1078
+ /// AcqRel | AcqRel | Acquire
1079
+ /// SeqCst | SeqCst | SeqCst
1080
+ ///
1081
+ /// `compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds,
1082
+ /// which allows the compiler to generate better assembly code when the compare and swap
1083
+ /// is used in a loop.
1084
+ ///
1051
1085
/// # Examples
1052
1086
///
1053
1087
/// ```
@@ -1575,6 +1609,23 @@ happens, and using [`Release`] makes the load part [`Relaxed`].
1575
1609
**Note**: This method is only available on platforms that support atomic
1576
1610
operations on [`" , $s_int_type, "`](" , $int_ref, ").
1577
1611
1612
+ # Migrating to `compare_exchange` and `compare_exchange_weak`
1613
+
1614
+ `compare_and_swap` is equivalent to `compare_exchange` with the following mapping for
1615
+ memory orderings:
1616
+
1617
+ Original | Success | Failure
1618
+ -------- | ------- | -------
1619
+ Relaxed | Relaxed | Relaxed
1620
+ Acquire | Acquire | Acquire
1621
+ Release | Release | Relaxed
1622
+ AcqRel | AcqRel | Acquire
1623
+ SeqCst | SeqCst | SeqCst
1624
+
1625
+ `compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds,
1626
+ which allows the compiler to generate better assembly code when the compare and swap
1627
+ is used in a loop.
1628
+
1578
1629
# Examples
1579
1630
1580
1631
```
0 commit comments