shines77 / RingQueue

A lock-free(or spin-lock) Queue implemented by RingBuffer.
MIT License
124 stars 55 forks source link

bug 描述 #2

Open sunmp opened 3 months ago

sunmp commented 3 months ago

经过分析测试你的代码q3_new.h,会有bug。 1、代码中第66行 if ((head - tail) > mask) 需要修改为 if ((uint32_t)(head - tail) > mask) ,否则发生反转的时候,队列满了,但忍让能够入队,最终导致数据丢失。 2、代码中96行,判空的地方,只需要head==tail的情况即为队列空,不过 || 后面的条件永远都无法触发,倒也不会产生bug。

shines77 commented 1 month ago

q3_new.h 代码只是douban(豆瓣)上的备份, 具体帖子已经忘记了, 项目中没有用到