Repository navigation
[kernel] 被动挂起的线程,无法处理信号 - #7663
weidongshan wants to merge 1 commit into
Conversation
|
有个题外话。导致这个问题的直接原因 —— 调用 Lines 966 to 982 in 307e9e5
|
使用rt_thread_suspend 暂停其他线程确实不是一个好的编程习惯,因为你不知道别的线程暂停时需要做什么额外的工作。比如要暂停一个音乐播放器,你使用rt_thread_suspend 的话,也许它会发出一个恒定不变的声音(比如使用PWM播放音乐时就会这样)。 |
|
For anyone following this PR: the scenario from the discussion below no longer reproduces on current master (RT-Thread 5.3.1), so the patch is probably obsolete. Measured on That is: Also note that Since the behaviour was not covered by any test, I added a regression case for it instead: |
拉取/合并请求描述:(PR description)
[
如果一个线程不是调用rt_thread_delay等函数主动进入挂起状态,不是在rt_schedule函数中放弃运行,
那么其他线程给它发信号时,它是不会执行信号处理函数的。
这个Bug的原因在于:在_signal_deliver函数中,发现目标线程处于挂起状态时,
只做了3件事:把它唤醒、设置线程状态为RT_THREAD_STAT_SIGNAL_PENDING、调用rt_schedule。
我们期望目标线程被唤醒后,从rt_schedule继续运行时,发现线程状态为RT_THREAD_STAT_SIGNAL_PENDING时调用信号处理函数。
但是,目标线程挂起时,不一定是在rt_schedule函数中放弃运行,比如它可能是被其他线程调用rt_thread_suspend挂起的。
这时候,目标线程不会执行信号处理函数。
为什么提交这份PR (why to submit this PR)
你的解决方案是什么 (what is your solution)
修改了src/signal.c,即使目标线程处于挂起状态,也是去修改它的栈。
在什么测试环境下测试通过 (what is the test environment)
可以如下复现这个Bug:创建2个线程,让thread2挂起thread1,然后给thread1发信号。示例代码如下:
`static void thread1_entry(void *parameter)
{
const char *thread_name = parameter;
int cnt = 0;
}
/* 线程2的入口函数 */
static void thread2_entry(void *parameter)
{
const char *thread_name = parameter;
int cnt = 0;
}`
]
当前拉取/合并请求的状态 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