Skip to content

Commit e8d334c

Browse files
committed
extend some comments regarding weak memory emulation
1 parent 0976d10 commit e8d334c

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/concurrency/data_race.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,25 @@ pub(super) struct ThreadClockSet {
108108
fence_acquire: VClock,
109109

110110
/// The last timestamp of happens-before relations that
111-
/// have been released by this thread by a fence.
111+
/// have been released by this thread by a release fence.
112112
fence_release: VClock,
113113

114114
/// Timestamps of the last SC fence performed by each
115-
/// thread, updated when this thread performs an SC fence
115+
/// thread, updated when this thread performs an SC fence.
116+
/// This is never acquired into the thread's clock, it
117+
/// just limits which old writes can be seen in weak memory emulation.
116118
pub(super) fence_seqcst: VClock,
117119

118120
/// Timestamps of the last SC write performed by each
119-
/// thread, updated when this thread performs an SC fence
121+
/// thread, updated when this thread performs an SC fence.
122+
/// This is never acquired into the thread's clock, it
123+
/// just limits which old writes can be seen in weak memory emulation.
120124
pub(super) write_seqcst: VClock,
121125

122126
/// Timestamps of the last SC fence performed by each
123-
/// thread, updated when this thread performs an SC read
127+
/// thread, updated when this thread performs an SC read.
128+
/// This is never acquired into the thread's clock, it
129+
/// just limits which old writes can be seen in weak memory emulation.
124130
pub(super) read_seqcst: VClock,
125131
}
126132

src/concurrency/weak_memory.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
//! Specifically, if an SC load reads from an atomic store of any ordering, then a later SC load cannot read from
1616
//! an earlier store in the location's modification order. This is to prevent creating a backwards S edge from the second
1717
//! load to the first, as a result of C++20's coherence-ordered before rules.
18+
//! (This seems to rule out behaviors that were actually permitted by the RC11 model that C++20
19+
//! intended to copy (https://plv.mpi-sws.org/scfix/paper.pdf); a change was introduced when
20+
//! translating the math to English. According to Viktor Vafeiadis, this difference is harmless. So
21+
//! we stick to what the standard says, and allow fewer behaviors.)
1822
//!
1923
//! Rust follows the C++20 memory model (except for the Consume ordering and some operations not performable through C++'s
2024
//! `std::atomic<T>` API). It is therefore possible for this implementation to generate behaviours never observable when the
@@ -138,6 +142,7 @@ struct StoreElement {
138142

139143
/// The timestamp of the storing thread when it performed the store
140144
timestamp: VTimestamp,
145+
141146
/// The value of this store. `None` means uninitialized.
142147
// FIXME: Currently, we cannot represent partial initialization.
143148
val: Option<Scalar>,
@@ -356,9 +361,9 @@ impl<'tcx> StoreBuffer {
356361
false
357362
} else if is_seqcst && store_elem.load_info.borrow().sc_loaded {
358363
// The current SC load cannot read-before a store that an earlier SC load has observed.
359-
// See https://github.com/rust-lang/miri/issues/2301#issuecomment-1222720427
364+
// See https://github.com/rust-lang/miri/issues/2301#issuecomment-1222720427.
360365
// Consequences of C++20 §31.4 [atomics.order] paragraph 3.1, 3.3 (coherence-ordered before)
361-
// and 4.1 (coherence-ordered before between SC makes global total order S)
366+
// and 4.1 (coherence-ordered before between SC makes global total order S).
362367
false
363368
} else {
364369
true

0 commit comments

Comments
 (0)