Skip to content

Commit b2f608b

Browse files
committed
Improve SC comments
1 parent ab88e64 commit b2f608b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/concurrency/weak_memory.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -320,31 +320,35 @@ impl<'mir, 'tcx: 'mir> StoreBuffer {
320320
keep_searching = if store_elem.timestamp <= clocks.clock[store_elem.store_index] {
321321
// CoWR: if a store happens-before the current load,
322322
// then we can't read-from anything earlier in modification order.
323+
// C++20 §6.9.2.2 [intro.races] paragraph 18
323324
log::info!("Stopping due to coherent write-read");
324325
false
325326
} else if store_elem.loads.borrow().iter().any(|(&load_index, &load_timestamp)| {
326327
load_timestamp <= clocks.clock[load_index]
327328
}) {
328329
// CoRR: if there was a load from this store which happened-before the current load,
329330
// then we cannot read-from anything earlier in modification order.
331+
// C++20 §6.9.2.2 [intro.races] paragraph 16
330332
log::info!("Stopping due to coherent read-read");
331333
false
332334
} else if store_elem.timestamp <= clocks.fence_seqcst[store_elem.store_index] {
333-
// The current load, which may be sequenced-after an SC fence, can only read-from
334-
// the last store sequenced-before an SC fence in another thread (or any stores
335-
// later than that SC fence)
335+
// The current load, which may be sequenced-after an SC fence, cannot read-before
336+
// the last store sequenced-before an SC fence in another thread.
337+
// C++17 §32.4 [atomics.order] paragraph 6
336338
log::info!("Stopping due to coherent load sequenced after sc fence");
337339
false
338340
} else if store_elem.timestamp <= clocks.write_seqcst[store_elem.store_index]
339341
&& store_elem.is_seqcst
340342
{
341-
// The current non-SC load can only read-from the latest SC store (or any stores later than that
342-
// SC store)
343+
// The current non-SC load, which may be sequenced-after an SC fence,
344+
// cannot read-before the last SC store executed before the fence.
345+
// C++17 §32.4 [atomics.order] paragraph 4
343346
log::info!("Stopping due to needing to load from the last SC store");
344347
false
345348
} else if is_seqcst && store_elem.timestamp <= clocks.read_seqcst[store_elem.store_index] {
346-
// The current SC load can only read-from the last store sequenced-before
347-
// the last SC fence (or any stores later than the SC fence)
349+
// The current SC load cannot read-before the last store sequenced-before
350+
// the last SC fence.
351+
// C++17 §32.4 [atomics.order] paragraph 5
348352
log::info!("Stopping due to sc load needing to load from the last SC store before an SC fence");
349353
false
350354
} else {true};

0 commit comments

Comments
 (0)