Fix logic bugs and destruction safety in block_queue#321
Open
paranoia986 wants to merge 1 commit intoqinguoyi:masterfrom
Open
Fix logic bugs and destruction safety in block_queue#321paranoia986 wants to merge 1 commit intoqinguoyi:masterfrom
paranoia986 wants to merge 1 commit intoqinguoyi:masterfrom
Conversation
124c596 to
70015fa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
在压力测试过程中,我修复了 block_queue 组件中的几个关键逻辑问题:
索引错误:修复了 front() 函数在初始状态下可能访问 m_array[-1] 的问题。
时间计算:修正了 pop(timeout) 中毫秒转纳秒的计算错误,尽管别的PR已经提交类似代码,仍然希望将其整合进我的实现逻辑中。
析构安全:引入 m_close 标志位并在析构时调用 broadcast(),防止线程在对象销毁时访问已释放内存。
虚假唤醒:将 pop 中的 if 改为 while 以符合多线程编程规范。
已通过 1000 并发压测,结果为 0 失败。