diff --git a/kernel/thread_abort.c b/kernel/thread_abort.c index eeb3db9f84c..61bca7ff28d 100644 --- a/kernel/thread_abort.c +++ b/kernel/thread_abort.c @@ -43,7 +43,19 @@ void z_impl_k_thread_abort(k_tid_t thread) z_thread_single_abort(thread); z_thread_monitor_exit(thread); - z_reschedule(&lock, key); + if (thread == _current && !z_is_in_isr()) { + z_swap(&lock, key); + } else { + /* Really, there's no good reason for this to be a + * scheduling point if we aren't aborting _current (by + * definition, no higher priority thread is runnable, + * because we're running!). But it always has been + * and is thus part of our API, and we have tests that + * rely on k_thread_abort() scheduling out of + * cooperative threads. + */ + z_reschedule(&lock, key); + } } #endif