Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add failing test case: atomic load on drop after panic #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions tests/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,39 @@ fn invalid_get_mut() {
let _ = unsafe { *(*v1.get()).get_mut() };
});
}

#[test]
#[should_panic]
fn atomic_load_on_drop_in_panic_crashes() {
struct AtomicLoadOnDrop(AtomicUsize);

impl AtomicLoadOnDrop {
fn new() -> Self {
Self(AtomicUsize::new(0))
}
}

impl Drop for AtomicLoadOnDrop {
fn drop(&mut self) {
let _ = self.0.load(SeqCst);
}
}

loom::model(|| {
let a = AtomicLoadOnDrop::new();

// Moving `AtomicLoadOnDrop` into a thread will trigger `drop` when the
// thread is dropped.
thread::spawn(move || {
let _a = a;
});

// Panic the parent thread.
//
// Without a fix, the `AtomicLoadOnDrop` drops _after_ the
// `loom::rt::scheduler::STATE` thread local is dropped. Since atomics
// use `STATE` to track accesses, dropping `AtomicLoadOnDrop` causes an
// access to an unset `RefCell`.
panic!();
});
}