crossbeam
crossbeam copied to clipboard
crossbeam-skiplist bug
[dependencies] crossbeam-skiplist = "0.1.1"
fn main() {
let map: Arc<SkipMap<u32, u32>> = Arc::new(SkipMap::new());
map.insert(1, 2);
let map1 = map.clone();
std::thread::spawn(move||{
let key = 1;
for _ in 0..10_0000 {
let len = map1.len();
if let Some(entry) = map1.get(&key) {
}else{
panic!("len={},key={}",len,key);
}
std::thread::sleep(Duration::from_millis(1));
}
});
for _ in 0..10_0000 {
map.insert(1, 2);
std::thread::sleep(Duration::from_millis(100));
}
}
output:
thread '<unnamed>' panicked at 'len=1,key=1', src\main.rs:21:17
stack backtrace:
Thanks for the report!
IIUC, insert reduces the refcount of the old value and then sets the new value, so if insert makes the refcount zero, a get that occurs between the time the refcount is reduced and the new value is set will return None because it sees a deleted value with a refcount of zero.
Do you have any plans to fix it
I consider it a bug that needs to be fixed, but I'm not sure if I will be able to work on a fix anytime soon. It would be great if you or someone else could work on a fix.
I consider it a bug that needs to be fixed, but I'm not sure if I will be able to work on a fix anytime soon. It would be great if you or someone else could work on a fix.
I am trying to fix it. https://github.com/crossbeam-rs/crossbeam/pull/1101