Skip to content

Commit

Permalink
Add regression test for miri
Browse files Browse the repository at this point in the history
  • Loading branch information
james7132 authored and Amanieu committed Feb 20, 2024
1 parent 9a2214e commit 8c739d0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ mod tests {
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::Relaxed;
use std::sync::Arc;
use std::hint::black_box;
use std::thread;

fn make_create() -> Arc<dyn Fn() -> usize + Send + Sync> {
Expand Down Expand Up @@ -609,6 +610,28 @@ mod tests {
assert_eq!(vec![1, 2, 3], v);
}

#[test]
fn miri_iter_soundness_check() {
let tls = Arc::new(ThreadLocal::new());
let _local = tls.get_or(|| Box::new(1));

let tls2 = tls.clone();
let join_1 = thread::spawn(move || {
let _tls = tls2.get_or(|| Box::new(2));
let iter = tls2.iter();
for item in iter {
black_box(item);
}
});

let iter = tls.iter();
for item in iter {
black_box(item);
}

join_1.join().ok();
}

#[test]
fn test_drop() {
let local = ThreadLocal::new();
Expand Down

0 comments on commit 8c739d0

Please sign in to comment.