rigtorp / MPMCQueue

A bounded multi-producer multi-consumer concurrent queue written in C++11
MIT License
1.15k stars 159 forks source link

BUG: can't Push if head_ overflow? #40

Closed esrrhs closed 10 months ago

esrrhs commented 10 months ago

I read the code, and found if the head overflow, then it can't Push anymore. and I change the head type from size_t to uint16_t, and just run code:

MPMCQueue<size_t> mp(1024);
for (size_t i = 0; i < UINT64_MAX; ++i) {
    mp.push(i);
    size_t j = 0;
    if (!mp.try_pop(j)) {
        std::cout << "failed " << i << std::endl;
        break;
    }
    std::cout << "success " << i << std::endl;
}

and then it stop cout at 65535 and then dead

success 65533
success 65534
success 65535
esrrhs commented 10 months ago

so if I use the queue a long time, the size_t will has the same problem. or this is just ok? because the time may be very long?

esrrhs commented 10 months ago

I run a test at my computer, found there will be thousand of years to make the size_t overflow. okay, I should not consider that situation :)

rigtorp commented 10 months ago

Yeah, the idea is that the 64 bit counter is huge and will never overflow. You bring up a good point, it would be nice to find a way to cleanly handle the overflow.

On Mon, Sep 18, 2023 at 7:39 AM esrrhs @.***> wrote:

Closed #40 https://github.com/rigtorp/MPMCQueue/issues/40 as completed.

— Reply to this email directly, view it on GitHub https://github.com/rigtorp/MPMCQueue/issues/40#event-10397442183, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABLO2433QBGIJFFQ5HH4DDX3A6IHANCNFSM6AAAAAA44SYUFE . You are receiving this because you are subscribed to this thread.Message ID: @.***>