pthread: fixed pthread_cancel and pthread_exit crash in SMP mode

1. When pthread exit, set the default cancellability state to NONCANCELABLE state.
2. Make sure modify tcb->flags is atomic operations.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
This commit is contained in:
zhangyuan21 2023-01-17 14:38:01 +08:00 committed by Xiang Xiao
parent 9fd30c7f63
commit acd108a5ed
2 changed files with 4 additions and 6 deletions

View File

@ -58,9 +58,7 @@ void pthread_exit(FAR void *exit_value)
* 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(tls_get_info());

View File

@ -469,14 +469,14 @@ void nxtask_exithook(FAR struct tcb_s *tcb, int status)
}
#endif
#ifdef CONFIG_SMP
leave_critical_section(flags);
#endif
/* This function can be re-entered in certain cases. Set a flag
* bit in the TCB to not that we have already completed this exit
* processing.
*/
tcb->flags |= TCB_FLAG_EXIT_PROCESSING;
#ifdef CONFIG_SMP
leave_critical_section(flags);
#endif
}