crossbeam icon indicating copy to clipboard operation
crossbeam copied to clipboard

crossbeam-skiplist bug

Open vnt-dev opened this issue 1 year ago • 3 comments

[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:

vnt-dev avatar Aug 27 '23 03:08 vnt-dev

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.

taiki-e avatar Sep 12 '23 12:09 taiki-e

Do you have any plans to fix it

vnt-dev avatar Sep 15 '23 14:09 vnt-dev

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.

taiki-e avatar Sep 15 '23 14:09 taiki-e

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

Tianion avatar Apr 12 '24 12:04 Tianion