From a1feba678d5e14e240183ba775b799384f0708e1 Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Mon, 11 Nov 2013 21:04:38 +0100 Subject: [PATCH] kernel/undertaker: Make sure the thread isn't running anymore --- src/system/kernel/thread.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/system/kernel/thread.cpp b/src/system/kernel/thread.cpp index 7b1cdcbcde..a2cebdbb37 100644 --- a/src/system/kernel/thread.cpp +++ b/src/system/kernel/thread.cpp @@ -1112,6 +1112,11 @@ undertaker(void* /*args*/) // we've got an entry Thread* thread = entry.thread; + // make sure the thread isn't running anymore + InterruptsSpinLocker schedulerLocker(thread->scheduler_lock); + ASSERT(thread->state == THREAD_STATE_FREE_ON_RESCHED); + schedulerLocker.Unlock(); + // remove this thread from from the kernel team -- this makes it // unaccessible Team* kernelTeam = team_get_kernel_team(); @@ -2254,12 +2259,13 @@ thread_exit(void) disable_interrupts(); + SpinLocker schedulerLocker(thread->scheduler_lock); + SpinLocker undertakerLocker(sUndertakerLock); sUndertakerEntries.Add(&undertakerEntry); sUndertakerCondition.NotifyOne(); undertakerLocker.Unlock(); - SpinLocker schedulerLocker(thread->scheduler_lock); thread->next_state = THREAD_STATE_FREE_ON_RESCHED; scheduler_reschedule();