Skip to content

Commit dbcba2f

Browse files
Christopher Friedtcfriedt
authored andcommitted
posix: pthread: check canceltype before async cancel
The default pthread cancellation type is deferred. Check that the canceltype is asynchronous (with respect to cancellation points) before cancelling a thread. Signed-off-by: Christopher Friedt <[email protected]>
1 parent 301581a commit dbcba2f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/posix/pthread.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ int pthread_setcanceltype(int type, int *oldtype)
638638
int pthread_cancel(pthread_t pthread)
639639
{
640640
int cancel_state;
641+
int cancel_type;
641642
k_spinlock_key_t key;
642643
struct posix_thread *t;
643644

@@ -649,9 +650,11 @@ int pthread_cancel(pthread_t pthread)
649650
key = k_spin_lock(&pthread_pool_lock);
650651
t->cancel_pending = true;
651652
cancel_state = t->cancel_state;
653+
cancel_type = t->cancel_type;
652654
k_spin_unlock(&pthread_pool_lock, key);
653655

654-
if (cancel_state == PTHREAD_CANCEL_ENABLE) {
656+
if (cancel_state == PTHREAD_CANCEL_ENABLE &&
657+
cancel_type == PTHREAD_CANCEL_ASYNCHRONOUS) {
655658
posix_thread_finalize(t, PTHREAD_CANCELED);
656659
}
657660

0 commit comments

Comments
 (0)