Skip to content

Commit 3d28a1a

Browse files
committed
Warn about safety of fetch_update
Specifically as it relates to the ABA problem.
1 parent 1ce5198 commit 3d28a1a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

library/core/src/sync/atomic.rs

+26
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,14 @@ impl AtomicBool {
955955
/// **Note:** This method is only available on platforms that support atomic
956956
/// operations on `u8`.
957957
///
958+
/// # Considerations
959+
///
960+
/// This method is not magic; it is not provided by the hardware.
961+
/// It is implemented in terms of [`AtomicBool::compare_exchange_weak`], and suffers from the same drawbacks.
962+
/// In particular, this method will not circumvent the [ABA Problem].
963+
///
964+
/// [ABA Problem]: https://en.wikipedia.org/wiki/ABA_problem
965+
///
958966
/// # Examples
959967
///
960968
/// ```rust
@@ -1422,6 +1430,14 @@ impl<T> AtomicPtr<T> {
14221430
/// **Note:** This method is only available on platforms that support atomic
14231431
/// operations on pointers.
14241432
///
1433+
/// # Considerations
1434+
///
1435+
/// This method is not magic; it is not provided by the hardware.
1436+
/// It is implemented in terms of [`AtomicPtr::compare_exchange_weak`], and suffers from the same drawbacks.
1437+
/// In particular, this method will not circumvent the [ABA Problem].
1438+
///
1439+
/// [ABA Problem]: https://en.wikipedia.org/wiki/ABA_problem
1440+
///
14251441
/// # Examples
14261442
///
14271443
/// ```rust
@@ -2510,6 +2526,16 @@ macro_rules! atomic_int {
25102526
/// **Note**: This method is only available on platforms that support atomic operations on
25112527
#[doc = concat!("[`", $s_int_type, "`].")]
25122528
///
2529+
/// # Considerations
2530+
///
2531+
/// This method is not magic; it is not provided by the hardware.
2532+
/// It is implemented in terms of
2533+
#[doc = concat!("[`", stringify!($atomic_type), "::compare_exchange_weak`],")]
2534+
/// and suffers from the same drawbacks.
2535+
/// In particular, this method will not circumvent the [ABA Problem].
2536+
///
2537+
/// [ABA Problem]: https://en.wikipedia.org/wiki/ABA_problem
2538+
///
25132539
/// # Examples
25142540
///
25152541
/// ```rust

0 commit comments

Comments
 (0)