From 671c5dc3d88adb9c9da5a87a3a1c19f02ee8548a Mon Sep 17 00:00:00 2001 From: zhangyuan21 Date: Wed, 24 May 2023 08:39:40 +0800 Subject: [PATCH] sched/pthread: Don't do cancel when it is already in the exit process When the task is already in the exit process, do not execute pthread cancel and return ESRCH. Signed-off-by: zhangyuan21 --- sched/pthread/pthread_cancel.c | 7 +++++++ sched/signal/sig_dispatch.c | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/sched/pthread/pthread_cancel.c b/sched/pthread/pthread_cancel.c index af9f71b269..613a0837cf 100644 --- a/sched/pthread/pthread_cancel.c +++ b/sched/pthread/pthread_cancel.c @@ -65,6 +65,13 @@ int pthread_cancel(pthread_t thread) return ESRCH; } + /* Return ESRCH when thread was in exit processing */ + + if ((tcb->flags & TCB_FLAG_EXIT_PROCESSING) != 0) + { + return ESRCH; + } + /* Only pthreads should use this interface */ DEBUGASSERT((tcb->flags & TCB_FLAG_TTYPE_MASK) == diff --git a/sched/signal/sig_dispatch.c b/sched/signal/sig_dispatch.c index fe091ebfda..2bffa2f29a 100644 --- a/sched/signal/sig_dispatch.c +++ b/sched/signal/sig_dispatch.c @@ -328,6 +328,13 @@ int nxsig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t *info) DEBUGASSERT(stcb != NULL && info != NULL); + /* Return ESRCH when thread was in exit processing */ + + if ((stcb->flags & TCB_FLAG_EXIT_PROCESSING) != 0) + { + return -ESRCH; + } + /* Don't actually send a signal for signo 0. */ if (info->si_signo == 0)