Skip to content

Commit 3268f56

Browse files
committed
Fix review changes
1 parent 0b0264f commit 3268f56

File tree

8 files changed

+43
-16
lines changed

8 files changed

+43
-16
lines changed

src/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl MemoryExtra {
150150
};
151151
let data_race = if config.data_race_detector {
152152
Some(Rc::new(data_race::GlobalState::new()))
153-
}else{
153+
} else {
154154
None
155155
};
156156
MemoryExtra {

src/shims/posix/linux/sync.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,10 @@ pub fn futex<'tcx>(
8585
// with the expected value, and starting to sleep are performed
8686
// atomically and totally ordered with respect to other futex
8787
// operations on the same futex word."
88-
// SeqCst is total order over all operations, so uses acquire,
89-
// either are equal under the current implementation.
90-
// FIXME: is Acquire correct or should some additional ordering constraints be observed?
91-
// FIXME: use RMW or similar?
88+
// SeqCst is total order over all operations.
89+
// FIXME: check if this should be changed when weak memory orders are added.
9290
let futex_val = this.read_scalar_at_offset_atomic(
93-
addr.into(), 0, this.machine.layouts.i32, AtomicReadOp::Acquire
91+
addr.into(), 0, this.machine.layouts.i32, AtomicReadOp::SeqCst
9492
)?.to_i32()?;
9593
if val == futex_val {
9694
// The value still matches, so we block the trait make it wait for FUTEX_WAKE.

src/sync.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ struct Mutex {
6161
lock_count: usize,
6262
/// The queue of threads waiting for this mutex.
6363
queue: VecDeque<ThreadId>,
64-
/// Data race handle
64+
/// Data race handle, this tracks the happens-before
65+
/// relationship between each mutex access. It is
66+
/// released to during unlock and acquired from during
67+
/// locking, and therefore stores the clock of the last
68+
/// thread to release this mutex.
6569
data_race: VClock
6670
}
6771

@@ -79,9 +83,24 @@ struct RwLock {
7983
writer_queue: VecDeque<ThreadId>,
8084
/// The queue of reader threads waiting for this lock.
8185
reader_queue: VecDeque<ThreadId>,
82-
/// Data race handle for writers
86+
/// Data race handle for writers, tracks the happens-before
87+
/// ordering between each write access to a rwlock and is updated
88+
/// after a sequence of concurrent readers to track the happens-
89+
/// before ordering between the set of previous readers and
90+
/// the current writer.
91+
/// Contains the clock of the last thread to release a writer
92+
/// lock or the joined clock of the set of last threads to release
93+
/// shared reader locks.
8394
data_race: VClock,
84-
/// Data race handle for readers
95+
/// Data race handle for readers, this is temporary storage
96+
/// for the combined happens-before ordering for between all
97+
/// concurrent readers and the next writer, and the value
98+
/// is stored to the main data_race variable once all
99+
/// readers are finished.
100+
/// Has to be stored separately since reader lock acquires
101+
/// must load the clock of the last write and must not
102+
/// add happens-before orderings between shared reader
103+
/// locks.
85104
data_race_reader: VClock,
86105
}
87106

@@ -100,13 +119,23 @@ struct CondvarWaiter {
100119
#[derive(Default, Debug)]
101120
struct Condvar {
102121
waiters: VecDeque<CondvarWaiter>,
122+
/// Tracks the happens-before relationship
123+
/// between a cond-var signal and a cond-var
124+
/// wait during a non-suprious signal event.
125+
/// Contains the clock of the last thread to
126+
/// perform a futex-signal.
103127
data_race: VClock,
104128
}
105129

106130
/// The futex state.
107131
#[derive(Default, Debug)]
108132
struct Futex {
109133
waiters: VecDeque<FutexWaiter>,
134+
/// Tracks the happens-before relationship
135+
/// between a futex-wake and a futex-wait
136+
/// during a non-spurious wake event.
137+
/// Contains the clock of the last thread to
138+
/// perform a futex-wake.
110139
data_race: VClock,
111140
}
112141

src/vector_clock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111

1212
/// A vector clock index, this is associated with a thread id
1313
/// but in some cases one vector index may be shared with
14-
/// multiple thread ids id it safe to do so.
14+
/// multiple thread ids if it safe to do so.
1515
#[derive(Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)]
1616
pub struct VectorIdx(u32);
1717

tests/compile-fail/data_race/relax_acquire_race.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn main() {
3131
let j3 = spawn(move || {
3232
if SYNC.load(Ordering::Acquire) == 2 {
3333
*c.0 //~ ERROR Data race
34-
}else{
34+
} else {
3535
0
3636
}
3737
});

tests/compile-fail/data_race/release_seq_race.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn main() {
3535
sleep(Duration::from_millis(1000));
3636
if SYNC.load(Ordering::Acquire) == 3 {
3737
*c.0 //~ ERROR Data race
38-
}else{
38+
} else {
3939
0
4040
}
4141
});

tests/compile-fail/data_race/rmw_race.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn main() {
3232
let j3 = spawn(move || {
3333
if SYNC.load(Ordering::Acquire) == 3 {
3434
*c.0 //~ ERROR Data race
35-
}else{
35+
} else {
3636
0
3737
}
3838
});

tests/run-pass/concurrency/data_race.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn test_fence_sync() {
2828
if SYNC.load(Ordering::Relaxed) == 1 {
2929
fence(Ordering::Acquire);
3030
unsafe { *evil_ptr.0 }
31-
}else{
31+
} else {
3232
0
3333
}
3434
});
@@ -77,7 +77,7 @@ pub fn test_rmw_no_block() {
7777
let j3 = spawn(move || {
7878
if SYNC.load(Ordering::Acquire) == 2 {
7979
*c.0
80-
}else{
80+
} else {
8181
0
8282
}
8383
});
@@ -104,7 +104,7 @@ pub fn test_release_no_block() {
104104
let j2 = spawn(move || {
105105
if SYNC.load(Ordering::Acquire) == 3 {
106106
*c.0
107-
}else{
107+
} else {
108108
0
109109
}
110110
});

0 commit comments

Comments
 (0)