From f6740c8a483a3d0d55f67fcacac139a9bb05a15e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 29 May 2022 13:26:09 +0200 Subject: [PATCH 1/2] clarify how Rust atomics correspond to C++ atomics --- core/src/sync/atomic.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/src/sync/atomic.rs b/core/src/sync/atomic.rs index 43cfb1bb6..9f4829e37 100644 --- a/core/src/sync/atomic.rs +++ b/core/src/sync/atomic.rs @@ -4,6 +4,12 @@ //! threads, and are the building blocks of other concurrent //! types. //! +//! Rust atomics follow the same rules as [C++20 atomics][cpp], specifically `atomic_ref`. +//! Basically, creating a *shared reference* to one of the Rust atomic types corresponds to creating +//! an `atomic_ref` in C++; the `atomic_ref` is destroyed when the lifetime of the shared reference +//! ends. (A Rust atomic type that is exclusively owned or behind a mutable reference does *not* +//! correspond to an "atomic object" in C++, since it can be accessed via non-atomic operations.) +//! //! This module defines atomic versions of a select number of primitive //! types, including [`AtomicBool`], [`AtomicIsize`], [`AtomicUsize`], //! [`AtomicI8`], [`AtomicU16`], etc. @@ -14,6 +20,7 @@ //! the memory barrier for that operation. These orderings are the //! same as the [C++20 atomic orderings][1]. For more information see the [nomicon][2]. //! +//! [cpp]: https://en.cppreference.com/w/cpp/atomic //! [1]: https://en.cppreference.com/w/cpp/atomic/memory_order //! [2]: ../../../nomicon/atomics.html //! From e22caaa41727545a02da8f5ebde4ff04fd888c35 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 21 Jun 2022 16:54:54 -0700 Subject: [PATCH 2/2] hedge our bets Co-authored-by: Josh Triplett --- core/src/sync/atomic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/sync/atomic.rs b/core/src/sync/atomic.rs index 9f4829e37..abd739654 100644 --- a/core/src/sync/atomic.rs +++ b/core/src/sync/atomic.rs @@ -4,7 +4,7 @@ //! threads, and are the building blocks of other concurrent //! types. //! -//! Rust atomics follow the same rules as [C++20 atomics][cpp], specifically `atomic_ref`. +//! Rust atomics currently follow the same rules as [C++20 atomics][cpp], specifically `atomic_ref`. //! Basically, creating a *shared reference* to one of the Rust atomic types corresponds to creating //! an `atomic_ref` in C++; the `atomic_ref` is destroyed when the lifetime of the shared reference //! ends. (A Rust atomic type that is exclusively owned or behind a mutable reference does *not*