Skip to content

Commit f4ba8b1

Browse files
committed
Improve SC comments
1 parent bb82124 commit f4ba8b1

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

0 commit comments

Comments
 (0)