Skip to content

修复 lab5b benchmark 中的 condition variable 和 mutex 用法 - #3

Merged
sakurs2 merged 1 commit into
sakurs2:masterfrom
SwingURM:fix/lab5b-bench
Oct 23, 2026
Merged

sakurs2 merged 1 commit into
sakurs2:masterfrom
SwingURM:fix/lab5b-bench

Conversation

@SwingURM

Copy link
Copy Markdown
Contributor

改了什么

  • thread pool 的任务按值捕获 i,避免任务运行时读到已经变化的循环变量。
  • 删除手动调用的 mutex.unlock();这里的 std::unique_lock 会负责解锁。
  • coroutine 中保留 lock guard,并对 cv.wait(...) 使用 co_await,确保等待完成后再继续执行。
  • 给 coroutine 版 notify_all 补上循环计算和 gid 更新,使它与另外两种实现做相同的工作。

Capture submitted task IDs by value, keep condition-variable locks under RAII, and await coroutine waits. Restore the notify-all workload so it performs the same loop and group progression as the other benchmark variants.
@sakurs2
sakurs2 merged commit 0230d9b into sakurs2:master Oct 23, 2026
@sakurs2

sakurs2 commented Oct 23, 2026

Copy link
Copy Markdown
Owner

感谢修复!这几处修改解决了 benchmark 中实际存在的问题:

  • 按值捕获 i,避免任务使用已经失效的循环变量。
  • 移除手动 unlock(),避免与 std::unique_lock 的析构重复解锁。
  • 保留协程锁 guard,并对 cv.wait(...) 使用 co_await,与现有 lab5b 测试中的用法一致。
  • 补齐协程版 notify_all 的计算和 gid 更新,使各实现的工作量一致。

已提取本 PR 的线程池和 STL 条件变量函数做隔离验证:notify_all 在 2、4、8 个工作线程下共运行 150 轮,notify_one 运行 50 轮、每个任务交替 1000 次,全部通过,AddressSanitizer 未报错。完整的 Linux 协程测试尚未运行,此验证仅覆盖 STL 部分。

已合入 master(0230d9b),谢谢贡献!

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.

2 participants