Skip to content

ThingBuf breaks a basic invariant under self-requeue test #98

@nodakai

Description

@nodakai
    #[test]
    fn test_() {
            fn to_vec<T: Clone + Default, const N: usize>(q: &StaticThingBuf<T, N>) -> Vec<T> {  // inaccurate
                let mut ret = vec![];
                while let Some(v) = q.pop() {
                    ret.push(v);
                }
                ret
            }
            const N: usize = 4;

            let q0 = StaticThingBuf::<u8, N>::new();
            for i in 0..N {
                q0.push(i as u8).expect("new enqueue");
            }
            eprintln!("start!");

            std::thread::scope(|sc| {
                for i in 0..2 {
                    sc.spawn(|| {
                        for k in 0..1000_000 {
                            if let Some(v) = q0.pop() {
                                q0.push(v).unwrap_or_else(|v| panic!("{}: q0 -> q0: {}, {:?}", k, v.into_inner(), to_vec(&q0)));
                            }
                        }
                    });
                }
            });

Confirmed an implementation based on a mutex, and another based on ring-channel didn't panic

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions