diff --git a/include/nuttx/tls.h b/include/nuttx/tls.h index ca8b80a0cd8e8..7c20ded05984b 100644 --- a/include/nuttx/tls.h +++ b/include/nuttx/tls.h @@ -66,6 +66,8 @@ # define TLS_INFO(sp) ((FAR struct tls_info_s *)((sp) & ~TLS_STACK_MASK)) #endif +#define TLS_THREAD_EIXT (1 << 0) + /**************************************************************************** * Public Types ****************************************************************************/ @@ -218,6 +220,7 @@ struct tls_info_s uint16_t tl_size; /* Actual size with alignments */ int tl_errno; /* Per-thread error number */ + int flags; /* Per-thread flags */ }; /**************************************************************************** diff --git a/libs/libc/pthread/pthread_exit.c b/libs/libc/pthread/pthread_exit.c index 412ddf8200bd9..cc4718c5b3e7a 100644 --- a/libs/libc/pthread/pthread_exit.c +++ b/libs/libc/pthread/pthread_exit.c @@ -55,6 +55,10 @@ void pthread_exit(FAR void *exit_value) { + FAR struct tls_info_s *info = tls_get_info(); + + info->flags |= TLS_THREAD_EIXT; + /* Mark the pthread as non-cancelable to avoid additional calls to * pthread_exit() due to any cancellation point logic that might get * kicked off by actions taken during pthread_exit processing. diff --git a/sched/signal/sig_default.c b/sched/signal/sig_default.c index 66c7c8ba96864..a01ad7d1e3451 100644 --- a/sched/signal/sig_default.c +++ b/sched/signal/sig_default.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "group/group.h" #include "sched/sched.h" @@ -230,12 +231,17 @@ static void nxsig_abnormal_termination(int signo) if ((rtcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD) { + FAR struct tls_info_s *info = tls_get_info(); + /* Exit the final thread of the task group. * * REVISIT: This will not work if HAVE_GROUP_MEMBERS is not set. */ - pthread_exit(NULL); + if ((info->flags & TLS_THREAD_EIXT) == 0) + { + pthread_exit(NULL); + } } else #endif