@@ -891,6 +891,19 @@ impl AtomicBool {
891
891
/// Err(false));
892
892
/// assert_eq!(some_bool.load(Ordering::Relaxed), false);
893
893
/// ```
894
+ ///
895
+ /// # Considerations
896
+ ///
897
+ /// `compare_exchange` is a [compare-and-swap operation] and suffers from the usual downsides
898
+ /// of CAS operations. In particular, a load of the value followed by a successful
899
+ /// `compare_exchange` with the previous load *does not ensure* that other threads have not
900
+ /// changed the value in the interim. This is usually important when the *equality* check in
901
+ /// the `compare_exchange` is being used to check the *identity* of a value, but equality
902
+ /// does not necessarily imply identity. In this case, `compare_exchange` can lead to the
903
+ /// [ABA problem].
904
+ ///
905
+ /// [ABA Problem]: https://en.wikipedia.org/wiki/ABA_problem
906
+ /// [compare-and-swap operation]: https://en.wikipedia.org/wiki/Compare-and-swap
894
907
#[ inline]
895
908
#[ stable( feature = "extended_compare_and_swap" , since = "1.10.0" ) ]
896
909
#[ doc( alias = "compare_and_swap" ) ]
@@ -973,6 +986,19 @@ impl AtomicBool {
973
986
/// }
974
987
/// }
975
988
/// ```
989
+ ///
990
+ /// # Considerations
991
+ ///
992
+ /// `compare_exchange` is a [compare-and-swap operation] and suffers from the usual downsides
993
+ /// of CAS operations. In particular, a load of the value followed by a successful
994
+ /// `compare_exchange` with the previous load *does not ensure* that other threads have not
995
+ /// changed the value in the interim. This is usually important when the *equality* check in
996
+ /// the `compare_exchange` is being used to check the *identity* of a value, but equality
997
+ /// does not necessarily imply identity. In this case, `compare_exchange` can lead to the
998
+ /// [ABA problem].
999
+ ///
1000
+ /// [ABA Problem]: https://en.wikipedia.org/wiki/ABA_problem
1001
+ /// [compare-and-swap operation]: https://en.wikipedia.org/wiki/Compare-and-swap
976
1002
#[ inline]
977
1003
#[ stable( feature = "extended_compare_and_swap" , since = "1.10.0" ) ]
978
1004
#[ doc( alias = "compare_and_swap" ) ]
@@ -1271,11 +1297,16 @@ impl AtomicBool {
1271
1297
///
1272
1298
/// # Considerations
1273
1299
///
1274
- /// This method is not magic; it is not provided by the hardware.
1275
- /// It is implemented in terms of [`AtomicBool::compare_exchange_weak`], and suffers from the same drawbacks.
1276
- /// In particular, this method will not circumvent the [ABA Problem].
1300
+ /// This method is not magic; it is not provided by the hardware, and does not act like a
1301
+ /// critical section or mutex. It is implemented in terms of
1302
+ /// [`compare_exchange`][Self::compare_exchange]\*, which is a [CAS operation], and thus
1303
+ /// suffers from the usual drawbacks of CAS operations, in particular the [ABA problem].
1304
+ ///
1305
+ /// \* It is actually implemented using [`compare_exchange_weak`][Self::compare_exchange_weak],
1306
+ /// but that distinction does not change the considerations inherent to a [CAS operation].
1277
1307
///
1278
1308
/// [ABA Problem]: https://en.wikipedia.org/wiki/ABA_problem
1309
+ /// [CAS operation]: https://en.wikipedia.org/wiki/Compare-and-swap
1279
1310
///
1280
1311
/// # Examples
1281
1312
///
@@ -1338,11 +1369,16 @@ impl AtomicBool {
1338
1369
///
1339
1370
/// # Considerations
1340
1371
///
1341
- /// This method is not magic; it is not provided by the hardware.
1342
- /// It is implemented in terms of [`AtomicBool::compare_exchange_weak`], and suffers from the same drawbacks.
1343
- /// In particular, this method will not circumvent the [ABA Problem].
1372
+ /// This method is not magic; it is not provided by the hardware, and does not act like a
1373
+ /// critical section or mutex. It is implemented in terms of
1374
+ /// [`compare_exchange`][Self::compare_exchange]\*, which is a [CAS operation], and thus
1375
+ /// suffers from the usual drawbacks of CAS operations, in particular the [ABA problem].
1376
+ ///
1377
+ /// \* It is actually implemented using [`compare_exchange_weak`][Self::compare_exchange_weak],
1378
+ /// but that distinction does not change the considerations inherent to a [CAS operation].
1344
1379
///
1345
1380
/// [ABA Problem]: https://en.wikipedia.org/wiki/ABA_problem
1381
+ /// [CAS operation]: https://en.wikipedia.org/wiki/Compare-and-swap
1346
1382
///
1347
1383
/// # Examples
1348
1384
///
@@ -1393,11 +1429,16 @@ impl AtomicBool {
1393
1429
///
1394
1430
/// # Considerations
1395
1431
///
1396
- /// This method is not magic; it is not provided by the hardware.
1397
- /// It is implemented in terms of [`AtomicBool::compare_exchange_weak`], and suffers from the same drawbacks.
1398
- /// In particular, this method will not circumvent the [ABA Problem].
1432
+ /// This method is not magic; it is not provided by the hardware, and does not act like a
1433
+ /// critical section or mutex. It is implemented in terms of
1434
+ /// [`compare_exchange`][Self::compare_exchange]\*, which is a [CAS operation], and thus
1435
+ /// suffers from the usual drawbacks of CAS operations, in particular the [ABA problem].
1436
+ ///
1437
+ /// \* It is actually implemented using [`compare_exchange_weak`][Self::compare_exchange_weak],
1438
+ /// but that distinction does not change the considerations inherent to a [CAS operation].
1399
1439
///
1400
1440
/// [ABA Problem]: https://en.wikipedia.org/wiki/ABA_problem
1441
+ /// [CAS operation]: https://en.wikipedia.org/wiki/Compare-and-swap
1401
1442
///
1402
1443
/// # Examples
1403
1444
///
@@ -1825,6 +1866,20 @@ impl<T> AtomicPtr<T> {
1825
1866
/// let value = some_ptr.compare_exchange(ptr, other_ptr,
1826
1867
/// Ordering::SeqCst, Ordering::Relaxed);
1827
1868
/// ```
1869
+ ///
1870
+ /// # Considerations
1871
+ ///
1872
+ /// `compare_exchange` is a [compare-and-swap operation] and suffers from the usual downsides
1873
+ /// of CAS operations. In particular, a load of the value followed by a successful
1874
+ /// `compare_exchange` with the previous load *does not ensure* that other threads have not
1875
+ /// changed the value in the interim. This is usually important when the *equality* check in
1876
+ /// the `compare_exchange` is being used to check the *identity* of a value, but equality
1877
+ /// does not necessarily imply identity. This is a particularly common case for pointers, as
1878
+ /// a pointer holding the same address does not imply that the same object exists at that
1879
+ /// address! In this case, `compare_exchange` can lead to the [ABA problem].
1880
+ ///
1881
+ /// [ABA Problem]: https://en.wikipedia.org/wiki/ABA_problem
1882
+ /// [compare-and-swap operation]: https://en.wikipedia.org/wiki/Compare-and-swap
1828
1883
#[ inline]
1829
1884
#[ stable( feature = "extended_compare_and_swap" , since = "1.10.0" ) ]
1830
1885
#[ cfg( target_has_atomic = "ptr" ) ]
@@ -1874,6 +1929,20 @@ impl<T> AtomicPtr<T> {
1874
1929
/// }
1875
1930
/// }
1876
1931
/// ```
1932
+ ///
1933
+ /// # Considerations
1934
+ ///
1935
+ /// `compare_exchange` is a [compare-and-swap operation] and suffers from the usual downsides
1936
+ /// of CAS operations. In particular, a load of the value followed by a successful
1937
+ /// `compare_exchange` with the previous load *does not ensure* that other threads have not
1938
+ /// changed the value in the interim. This is usually important when the *equality* check in
1939
+ /// the `compare_exchange` is being used to check the *identity* of a value, but equality
1940
+ /// does not necessarily imply identity. This is a particularly common case for pointers, as
1941
+ /// a pointer holding the same address does not imply that the same object exists at that
1942
+ /// address! In this case, `compare_exchange` can lead to the [ABA problem].
1943
+ ///
1944
+ /// [ABA Problem]: https://en.wikipedia.org/wiki/ABA_problem
1945
+ /// [compare-and-swap operation]: https://en.wikipedia.org/wiki/Compare-and-swap
1877
1946
#[ inline]
1878
1947
#[ stable( feature = "extended_compare_and_swap" , since = "1.10.0" ) ]
1879
1948
#[ cfg( target_has_atomic = "ptr" ) ]
@@ -1917,11 +1986,16 @@ impl<T> AtomicPtr<T> {
1917
1986
///
1918
1987
/// # Considerations
1919
1988
///
1920
- /// This method is not magic; it is not provided by the hardware.
1921
- /// It is implemented in terms of [`AtomicPtr::compare_exchange_weak`], and suffers from the same drawbacks.
1922
- /// In particular, this method will not circumvent the [ABA Problem].
1989
+ /// This method is not magic; it is not provided by the hardware, and does not act like a
1990
+ /// critical section or mutex. It is implemented in terms of
1991
+ /// [`compare_exchange`][Self::compare_exchange]\*, which is a [CAS operation], and thus
1992
+ /// suffers from the usual drawbacks of CAS operations, in particular the [ABA problem].
1993
+ ///
1994
+ /// \* It is actually implemented using [`compare_exchange_weak`][Self::compare_exchange_weak],
1995
+ /// but that distinction does not change the considerations inherent to a [CAS operation].
1923
1996
///
1924
1997
/// [ABA Problem]: https://en.wikipedia.org/wiki/ABA_problem
1998
+ /// [CAS operation]: https://en.wikipedia.org/wiki/Compare-and-swap
1925
1999
///
1926
2000
/// # Examples
1927
2001
///
@@ -1992,11 +2066,16 @@ impl<T> AtomicPtr<T> {
1992
2066
///
1993
2067
/// # Considerations
1994
2068
///
1995
- /// This method is not magic; it is not provided by the hardware.
1996
- /// It is implemented in terms of [`AtomicPtr::compare_exchange_weak`], and suffers from the same drawbacks.
1997
- /// In particular, this method will not circumvent the [ABA Problem].
2069
+ /// This method is not magic; it is not provided by the hardware, and does not act like a
2070
+ /// critical section or mutex. It is implemented in terms of
2071
+ /// [`compare_exchange`][Self::compare_exchange]\*, which is a [CAS operation], and thus
2072
+ /// suffers from the usual drawbacks of CAS operations, in particular the [ABA problem].
2073
+ ///
2074
+ /// \* It is actually implemented using [`compare_exchange_weak`][Self::compare_exchange_weak],
2075
+ /// but that distinction does not change the considerations inherent to a [CAS operation].
1998
2076
///
1999
2077
/// [ABA Problem]: https://en.wikipedia.org/wiki/ABA_problem
2078
+ /// [CAS operation]: https://en.wikipedia.org/wiki/Compare-and-swap
2000
2079
///
2001
2080
/// # Examples
2002
2081
///
@@ -2057,11 +2136,16 @@ impl<T> AtomicPtr<T> {
2057
2136
///
2058
2137
/// # Considerations
2059
2138
///
2060
- /// This method is not magic; it is not provided by the hardware.
2061
- /// It is implemented in terms of [`AtomicPtr::compare_exchange_weak`], and suffers from the same drawbacks.
2062
- /// In particular, this method will not circumvent the [ABA Problem].
2139
+ /// This method is not magic; it is not provided by the hardware, and does not act like a
2140
+ /// critical section or mutex. It is implemented in terms of
2141
+ /// [`compare_exchange`][Self::compare_exchange]\*, which is a [CAS operation], and thus
2142
+ /// suffers from the usual drawbacks of CAS operations, in particular the [ABA problem].
2143
+ ///
2144
+ /// \* It is actually implemented using [`compare_exchange_weak`][Self::compare_exchange_weak],
2145
+ /// but that distinction does not change the considerations inherent to a [CAS operation].
2063
2146
///
2064
2147
/// [ABA Problem]: https://en.wikipedia.org/wiki/ABA_problem
2148
+ /// [CAS operation]: https://en.wikipedia.org/wiki/Compare-and-swap
2065
2149
///
2066
2150
/// # Examples
2067
2151
///
@@ -2967,6 +3051,20 @@ macro_rules! atomic_int {
2967
3051
/// Err(10));
2968
3052
/// assert_eq!(some_var.load(Ordering::Relaxed), 10);
2969
3053
/// ```
3054
+ ///
3055
+ /// # Considerations
3056
+ ///
3057
+ /// `compare_exchange` is a [compare-and-swap operation] and suffers from the usual downsides
3058
+ /// of CAS operations. In particular, a load of the value followed by a successful
3059
+ /// `compare_exchange` with the previous load *does not ensure* that other threads have not
3060
+ /// changed the value in the interim! This is usually important when the *equality* check in
3061
+ /// the `compare_exchange` is being used to check the *identity* of a value, but equality
3062
+ /// does not necessarily imply identity. This is a particularly common case for pointers, as
3063
+ /// a pointer holding the same address does not imply that the same object exists at that
3064
+ /// address! In this case, `compare_exchange` can lead to the [ABA problem].
3065
+ ///
3066
+ /// [ABA Problem]: https://en.wikipedia.org/wiki/ABA_problem
3067
+ /// [compare-and-swap operation]: https://en.wikipedia.org/wiki/Compare-and-swap
2970
3068
#[ inline]
2971
3069
#[ $stable_cxchg]
2972
3070
#[ $cfg_cas]
@@ -3016,6 +3114,20 @@ macro_rules! atomic_int {
3016
3114
/// }
3017
3115
/// }
3018
3116
/// ```
3117
+ ///
3118
+ /// # Considerations
3119
+ ///
3120
+ /// `compare_exchange` is a [compare-and-swap operation] and suffers from the usual downsides
3121
+ /// of CAS operations. In particular, a load of the value followed by a successful
3122
+ /// `compare_exchange` with the previous load *does not ensure* that other threads have not
3123
+ /// changed the value in the interim. This is usually important when the *equality* check in
3124
+ /// the `compare_exchange` is being used to check the *identity* of a value, but equality
3125
+ /// does not necessarily imply identity. This is a particularly common case for pointers, as
3126
+ /// a pointer holding the same address does not imply that the same object exists at that
3127
+ /// address! In this case, `compare_exchange` can lead to the [ABA problem].
3128
+ ///
3129
+ /// [ABA Problem]: https://en.wikipedia.org/wiki/ABA_problem
3130
+ /// [compare-and-swap operation]: https://en.wikipedia.org/wiki/Compare-and-swap
3019
3131
#[ inline]
3020
3132
#[ $stable_cxchg]
3021
3133
#[ $cfg_cas]
@@ -3246,13 +3358,16 @@ macro_rules! atomic_int {
3246
3358
///
3247
3359
/// # Considerations
3248
3360
///
3249
- /// This method is not magic; it is not provided by the hardware.
3250
- /// It is implemented in terms of
3251
- #[ doc = concat!( "[`" , stringify!( $atomic_type) , "::compare_exchange_weak`]," ) ]
3252
- /// and suffers from the same drawbacks.
3253
- /// In particular, this method will not circumvent the [ABA Problem].
3361
+ /// This method is not magic; it is not provided by the hardware, and does not act like a
3362
+ /// critical section or mutex. It is implemented in terms of
3363
+ /// [`compare_exchange`][Self::compare_exchange]\*, which is a [CAS operation], and thus
3364
+ /// suffers from the usual drawbacks of CAS operations, in particular the [ABA problem].
3365
+ ///
3366
+ /// \* It is actually implemented using [`compare_exchange_weak`][Self::compare_exchange_weak],
3367
+ /// but that distinction does not change the considerations inherent to a [CAS operation].
3254
3368
///
3255
3369
/// [ABA Problem]: https://en.wikipedia.org/wiki/ABA_problem
3370
+ /// [CAS operation]: https://en.wikipedia.org/wiki/Compare-and-swap
3256
3371
///
3257
3372
/// # Examples
3258
3373
///
@@ -3309,13 +3424,16 @@ macro_rules! atomic_int {
3309
3424
///
3310
3425
/// # Considerations
3311
3426
///
3312
- /// This method is not magic; it is not provided by the hardware.
3313
- /// It is implemented in terms of
3314
- #[ doc = concat!( "[`" , stringify!( $atomic_type) , "::compare_exchange_weak`]," ) ]
3315
- /// and suffers from the same drawbacks.
3316
- /// In particular, this method will not circumvent the [ABA Problem].
3427
+ /// This method is not magic; it is not provided by the hardware, and does not act like a
3428
+ /// critical section or mutex. It is implemented in terms of
3429
+ /// [`compare_exchange`][Self::compare_exchange]\*, which is a [CAS operation], and thus
3430
+ /// suffers from the usual drawbacks of CAS operations, in particular the [ABA problem].
3431
+ ///
3432
+ /// \* It is actually implemented using [`compare_exchange_weak`][Self::compare_exchange_weak],
3433
+ /// but that distinction does not change the considerations inherent to a [CAS operation].
3317
3434
///
3318
3435
/// [ABA Problem]: https://en.wikipedia.org/wiki/ABA_problem
3436
+ /// [CAS operation]: https://en.wikipedia.org/wiki/Compare-and-swap
3319
3437
///
3320
3438
/// # Examples
3321
3439
///
@@ -3367,13 +3485,16 @@ macro_rules! atomic_int {
3367
3485
///
3368
3486
/// # Considerations
3369
3487
///
3370
- /// This method is not magic; it is not provided by the hardware.
3371
- /// It is implemented in terms of
3372
- #[ doc = concat!( "[`" , stringify!( $atomic_type) , "::compare_exchange_weak`]," ) ]
3373
- /// and suffers from the same drawbacks.
3374
- /// In particular, this method will not circumvent the [ABA Problem].
3488
+ /// This method is not magic; it is not provided by the hardware, and does not act like a
3489
+ /// critical section or mutex. It is implemented in terms of
3490
+ /// [`compare_exchange`][Self::compare_exchange]\*, which is a [CAS operation], and thus
3491
+ /// suffers from the usual drawbacks of CAS operations, in particular the [ABA problem].
3492
+ ///
3493
+ /// \* It is actually implemented using [`compare_exchange_weak`][Self::compare_exchange_weak],
3494
+ /// but that distinction does not change the considerations inherent to a [CAS operation].
3375
3495
///
3376
3496
/// [ABA Problem]: https://en.wikipedia.org/wiki/ABA_problem
3497
+ /// [CAS operation]: https://en.wikipedia.org/wiki/Compare-and-swap
3377
3498
///
3378
3499
/// # Examples
3379
3500
///
0 commit comments