diff --git a/libs/libc/pthread/pthread_exit.c b/libs/libc/pthread/pthread_exit.c index fce8f3ef35..c68ef6a7fa 100644 --- a/libs/libc/pthread/pthread_exit.c +++ b/libs/libc/pthread/pthread_exit.c @@ -54,6 +54,15 @@ void pthread_exit(FAR void *exit_value) { + /* 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. + */ + +#ifdef CONFIG_CANCELLATION_POINTS + task_setcancelstate(TASK_CANCEL_DISABLE, NULL); +#endif + #ifdef CONFIG_PTHREAD_CLEANUP pthread_cleanup_popall(up_tls_info()); #endif diff --git a/sched/pthread/pthread_exit.c b/sched/pthread/pthread_exit.c index 8ef8ee7e6e..22a7871e64 100644 --- a/sched/pthread/pthread_exit.c +++ b/sched/pthread/pthread_exit.c @@ -78,17 +78,6 @@ void nx_pthread_exit(FAR void *exit_value) nxsig_procmask(SIG_SETMASK, &set, NULL); -#ifdef CONFIG_CANCELLATION_POINTS - /* 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. - */ - - tcb->flags |= TCB_FLAG_NONCANCELABLE; - tcb->flags &= ~TCB_FLAG_CANCEL_PENDING; - tcb->cpcount = 0; -#endif - /* Complete pending join operations */ status = pthread_completejoin(getpid(), exit_value);