Repository navigation
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: kernelReviewers: @GorrayLi @ReviewSun @hamburger-os @lianux-mm @wdfk-prog @xu18838022837 Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-10-17 16:04 CST)
📝 Review Instructions
|
|
BernardXiong
left a comment
There was a problem hiding this comment.
Review / 审查
结论 / Conclusion: no blocking issue found in the duplicate-defunct protection.
The new flag is initialized with the scheduler context, and _thread_mark_defunct() makes the check-and-set atomic under the thread spinlock before mutex detachment and defunct enqueue. This addresses the duplicate enqueue/double cleanup scenario described by the PR, and the change is small and localized.
建议 / Suggestions
-
Please add an SMP-focused regression case, or document why the existing lock ordering is sufficient. The paths now combine the scheduler critical section, the thread spinlock, and mutex detachment; a test should exercise concurrent
rt_thread_delete()/rt_thread_detach()against natural thread exit. -
The new bit lives in
rt_sched_thread_ctx, whose other fields are generally accessed under scheduler-lock rules, while_thread_mark_defunct()uses the thread spinlock. Please add a short comment documenting thatsched_flag_defunctis intentionally protected bythread->spinlock, so future scheduler changes do not introduce a lock-domain mismatch. -
Keep the negative return behavior covered for both dynamic and static threads after natural exit, including repeated calls. The current tests cover the main cases; the SMP/race case is the remaining useful gap.
The PR description and test intent are clear. / PR 描述和测试意图清晰。
|
@BernardXiong 熊大,已经按照修改建议修复了 |
745bcd9 to
ec6c0ec
Compare
拉取/合并请求描述:(PR description)
为什么提交这份 PR (why to submit this PR)
线程自然退出、显式删除或分离后,在对象仍有效但尚未完成回收时再次调用
rt_thread_delete()/rt_thread_detach(),可能将同一线程重复加入 defunct 队列,造成链表破坏或重复清理。本 PR 为清理过程增加一次性保护。Prevent duplicate defunct enqueue and cleanup while the thread object is still valid.
你的解决方案是什么 (what is your solution)
struct rt_thread中增加独立的rt_uint8_t defunct字段,由公共初始化路径_thread_init()清零,覆盖动态创建、静态初始化及合法的重新初始化。_thread_mark_defunct()在thread->spinlock下完成检查和置位。标志表示“已取得清理权”,在 mutex 清理和入队之前设置,一次生命周期内不再清零。-RT_ERROR。Use a separate byte in the thread object, protected by the thread spinlock, to claim cleanup once per lifetime. This avoids sharing storage with scheduler bit-fields that use different locking.
修改文件 / Changed files
include/rtdef.h:增加独立的线程清理标志。src/thread.c:初始化标志,并在退出、删除和分离路径中保护一次性清理。src/utest/thread_tc.c:补充重复操作、静态对象复用和双核并发删除回归测试。测试覆盖 / Regression coverage
-RT_ERROR且只清理一次。RT_EOK、一次-RT_ERROR和一次 cleanup。请提供验证的 BSP 和 config (provide the config and BSP)
bsp/qemu-vexpress-a9,分别使用 UP(1 核)和 SMP(2 核)配置,均未启用 SMART。.config生成rtconfig.h,仓库 BSP 配置未改动。两种配置均在默认 BSP 配置上启用:
SMP 配置额外启用:
构建与运行命令:
QEMU 使用
-M vexpress-a9,UP 为-smp 1,SMP 为-smp 2。两次运行均输出:
git diff --check通过。在上述配置中,sizeof(struct rt_thread)分别由 UP 的 168 增至 172 字节、SMP 的 176 增至 180 字节;需重编依赖线程结构体布局的代码。验证范围 / Validation limits
上述结果是本地严格构建及 QEMU 单次回归结果,不代表全部 utest 或压力测试通过。AArch64 /
ARCH_USING_HW_THREAD_SELF的运行路径尚未实测;SMP 新增用例的目标未启动,不宣称覆盖运行中线程自然退出与远端删除的专项竞态。Both local UP and SMP strict builds and
core.thread_tcruns passed. AArch64 runtime behavior and the running-thread exit-versus-delete race were not tested.当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up