Skip to content

Fix logic bugs and destruction safety in block_queue#321

Open
paranoia986 wants to merge 1 commit intoqinguoyi:masterfrom
paranoia986:fix-block-queue-logic
Open

Fix logic bugs and destruction safety in block_queue#321
paranoia986 wants to merge 1 commit intoqinguoyi:masterfrom
paranoia986:fix-block-queue-logic

Conversation

@paranoia986
Copy link
Copy Markdown

在压力测试过程中,我修复了 block_queue 组件中的几个关键逻辑问题:

  1. 索引错误:修复了 front() 函数在初始状态下可能访问 m_array[-1] 的问题。

  2. 时间计算:修正了 pop(timeout) 中毫秒转纳秒的计算错误,尽管别的PR已经提交类似代码,仍然希望将其整合进我的实现逻辑中。

  3. 析构安全:引入 m_close 标志位并在析构时调用 broadcast(),防止线程在对象销毁时访问已释放内存。

  4. 虚假唤醒:将 pop 中的 if 改为 while 以符合多线程编程规范。

已通过 1000 并发压测,结果为 0 失败。

屏幕截图_20260313_172516

@paranoia986 paranoia986 force-pushed the fix-block-queue-logic branch from 124c596 to 70015fa Compare March 13, 2026 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant