Skip to content

Commit

Permalink
Add a loom model that checks for a race between leak and drop
Browse files Browse the repository at this point in the history
  • Loading branch information
thomcc committed May 7, 2024
1 parent 3c85a3b commit 609bdb3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/arc_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1678,4 +1678,20 @@ mod loomtest {
t2.join().unwrap();
});
}

#[test]
fn leak_drop() {
loom::model(|| {
let a1 = ArcStr::from("foo");
let a2 = a1.clone();

let t1 = thread::spawn(move || {
drop(a1);
});
let t2 = thread::spawn(move || a2.leak());
t1.join().unwrap();
let leaked: &'static str = t2.join().unwrap();
assert_eq!(leaked, "foo");
});
}
}

0 comments on commit 609bdb3

Please sign in to comment.