Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MpMcQueue: enqueue enters infinite loop if queue is full (N >= 256) #461

Closed
sjorsdewit opened this issue Feb 28, 2024 · 1 comment · Fixed by #462
Closed

MpMcQueue: enqueue enters infinite loop if queue is full (N >= 256) #461

sjorsdewit opened this issue Feb 28, 2024 · 1 comment · Fixed by #462
Labels

Comments

@sjorsdewit
Copy link

I'm using heapless-0.8.0 with the feature mpmc_large. Instances of MpMcQueue with N >= 256 can be constructed and appear to work correctly, but I think I found an edge case:

If the queue is already full and another enqueue is attempted, the function blocks in an inner busy loop. I suspect it has to do with the i8 it uses internally but replacing it with isize did not appear to fix this.

The issue can be reproduced by this test program:

#[test]
fn enqueue_full_256() {
    const CAPACITY: usize = 256;
    let q: MpMcQueue<u8, CAPACITY> = MpMcQueue::new();
    for n in 0..CAPACITY {
        // First CAPACITY enqueues are succesfull
        q.enqueue(0xAA).unwrap();
    }
    // Queue is full. This should fail, but instead triggers a busy loop for CAPACITY > 128
    q.enqueue(0x55).unwrap_err();
}
@reitermarkus
Copy link
Member

reitermarkus commented Feb 29, 2024

I haven't looked at the implementation in detail, but

let dif = (seq as i8).wrapping_sub((pos.wrapping_add(1)) as i8);

and

let dif = (seq as i8).wrapping_sub(pos as i8);

look suspicious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants