Skip to content

Commit

Permalink
Track location for atomic new/drop
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhoo committed Apr 9, 2020
1 parent 93c96d5 commit 2a073bf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/rt/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ impl<T: Numeric> Atomic<T> {
state.stores[index].value = T::into_u64(self.0);

if !std::thread::panicking() {
state
.unsync_mut_locations
.track(location!(), &execution.threads);
state.track_unsync_mut(&execution.threads);
}
});
Expand Down Expand Up @@ -358,6 +361,7 @@ impl State {
};

// All subsequent accesses must happen-after.
state.unsync_mut_locations.track(location, &threads);
state.track_unsync_mut(threads);

// Store the initial thread
Expand Down
8 changes: 4 additions & 4 deletions src/rt/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#[macro_use]
mod location;
pub(crate) use self::location::Location;

mod access;
use self::access::Access;

Expand All @@ -10,10 +14,6 @@ pub(crate) use self::arc::Arc;
mod atomic;
pub(crate) use self::atomic::{fence, Atomic};

#[macro_use]
mod location;
pub(crate) use self::location::Location;

mod cell;
pub(crate) use self::cell::Cell;

Expand Down
8 changes: 8 additions & 0 deletions tests/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ use loom::thread;
use std::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed, Release};
use std::sync::Arc;

#[test]
fn load_after_new() {
loom::model(|| {
let a = AtomicUsize::new(0);
a.load(Relaxed);
});
}

#[test]
#[should_panic]
fn invalid_unsync_load_relaxed() {
Expand Down

0 comments on commit 2a073bf

Please sign in to comment.