From f4ba8b1160477a99806d99cf461acf54bee70e92 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Thu, 25 Aug 2022 00:07:17 +0100 Subject: [PATCH] Improve SC comments --- src/concurrency/weak_memory.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/concurrency/weak_memory.rs b/src/concurrency/weak_memory.rs index 5a5c2c211bc9..a5f59137c22c 100644 --- a/src/concurrency/weak_memory.rs +++ b/src/concurrency/weak_memory.rs @@ -319,6 +319,7 @@ impl<'mir, 'tcx: 'mir> StoreBuffer { keep_searching = if store_elem.timestamp <= clocks.clock[store_elem.store_index] { // CoWR: if a store happens-before the current load, // then we can't read-from anything earlier in modification order. + // C++20 §6.9.2.2 [intro.races] paragraph 18 log::info!("Stopping due to coherent write-read"); false } else if store_elem.loads.borrow().iter().any(|(&load_index, &load_timestamp)| { @@ -326,24 +327,27 @@ impl<'mir, 'tcx: 'mir> StoreBuffer { }) { // CoRR: if there was a load from this store which happened-before the current load, // then we cannot read-from anything earlier in modification order. + // C++20 §6.9.2.2 [intro.races] paragraph 16 log::info!("Stopping due to coherent read-read"); false } else if store_elem.timestamp <= clocks.fence_seqcst[store_elem.store_index] { - // The current load, which may be sequenced-after an SC fence, can only read-from - // the last store sequenced-before an SC fence in another thread (or any stores - // later than that SC fence) + // The current load, which may be sequenced-after an SC fence, cannot read-before + // the last store sequenced-before an SC fence in another thread. + // C++17 §32.4 [atomics.order] paragraph 6 log::info!("Stopping due to coherent load sequenced after sc fence"); false } else if store_elem.timestamp <= clocks.write_seqcst[store_elem.store_index] && store_elem.is_seqcst { - // The current non-SC load can only read-from the latest SC store (or any stores later than that - // SC store) + // The current non-SC load, which may be sequenced-after an SC fence, + // cannot read-before the last SC store executed before the fence. + // C++17 §32.4 [atomics.order] paragraph 4 log::info!("Stopping due to needing to load from the last SC store"); false } else if is_seqcst && store_elem.timestamp <= clocks.read_seqcst[store_elem.store_index] { - // The current SC load can only read-from the last store sequenced-before - // the last SC fence (or any stores later than the SC fence) + // The current SC load cannot read-before the last store sequenced-before + // the last SC fence. + // C++17 §32.4 [atomics.order] paragraph 5 log::info!("Stopping due to sc load needing to load from the last SC store before an SC fence"); false } else {true};