From 5c7f08da10b2e2b407c77626bcb1066905cb6f74 Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Mon, 6 May 2024 17:49:06 -0700 Subject: [PATCH] Add a loom model that checks for a race between leak and drop --- src/arc_str.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/arc_str.rs b/src/arc_str.rs index cea71a8..9ad3550 100644 --- a/src/arc_str.rs +++ b/src/arc_str.rs @@ -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"); + }); + } }