I was experimenting with lockfree data structures inspired by this talk. I found this crate tux_lockfree which is a fork of lockfree crate (now unmaintained).
If you look at the multithreaded map example here, it is concurrently manipulating the key, under miri it runs fine.
But I am trying to update a single key from multiple threads, which makes miri fail.
let map = Arc::new(Map::new());
let mut threads = Vec::new();
for _ in 1i64..=10 {
let map = map.clone();
threads.push(thread::spawn(move || {
let prev = map.get("counter").map_or(1, |guard| *guard.val());
map.insert("counter", prev + 1);
// this one also fails
// map.insert_with("counter", |_, _, stored| {
// Preview::New(stored.map_or(1, |&(_, x)| x + 1))
// });
}));
}
for thread in threads {
thread.join().expect("thread failed");
}
assert_eq!(*map.get("counter").unwrap().val(), 10);