Skip to content

Commit 25b8449

Browse files
authored
Rollup merge of #97516 - RalfJung:atomics, r=joshtriplett
clarify how Rust atomics correspond to C++ atomics ``@cbeuw`` noted in rust-lang/miri#1963 that the correspondence between C++ atomics and Rust atomics is not quite as obvious as one might think, since in Rust I can use `get_mut` to treat previously non-atomic data as atomic. However, I think using C++20 `atomic_ref`, we can establish a suitable relation between the two -- or do you see problems with that ``@cbeuw?`` (I recall you said there was some issue, but it was deep inside that PR and Github makes it impossible to find...) Cc ``@thomcc;`` not sure whom else to ping for atomic memory model things.
2 parents 75a2e5d + 4768bfc commit 25b8449

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

library/core/src/sync/atomic.rs

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
//! threads, and are the building blocks of other concurrent
55
//! types.
66
//!
7+
//! Rust atomics currently follow the same rules as [C++20 atomics][cpp], specifically `atomic_ref`.
8+
//! Basically, creating a *shared reference* to one of the Rust atomic types corresponds to creating
9+
//! an `atomic_ref` in C++; the `atomic_ref` is destroyed when the lifetime of the shared reference
10+
//! ends. (A Rust atomic type that is exclusively owned or behind a mutable reference does *not*
11+
//! correspond to an "atomic object" in C++, since it can be accessed via non-atomic operations.)
12+
//!
713
//! This module defines atomic versions of a select number of primitive
814
//! types, including [`AtomicBool`], [`AtomicIsize`], [`AtomicUsize`],
915
//! [`AtomicI8`], [`AtomicU16`], etc.
@@ -14,6 +20,7 @@
1420
//! the memory barrier for that operation. These orderings are the
1521
//! same as the [C++20 atomic orderings][1]. For more information see the [nomicon][2].
1622
//!
23+
//! [cpp]: https://en.cppreference.com/w/cpp/atomic
1724
//! [1]: https://en.cppreference.com/w/cpp/atomic/memory_order
1825
//! [2]: ../../../nomicon/atomics.html
1926
//!

0 commit comments

Comments
 (0)