From b9cecdff97e290dc919de6bd318e6d6be5ee6d2d Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Mon, 12 Feb 2018 21:03:39 +0100 Subject: kern/thread: minor changes Make thread_runq_schedule() slightly more resilient by setting the next thread pointer to NULL after the context switch. --- kern/thread.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'kern/thread.c') diff --git a/kern/thread.c b/kern/thread.c index f41e5936..20378ffb 100644 --- a/kern/thread.c +++ b/kern/thread.c @@ -653,15 +653,18 @@ thread_runq_schedule(struct thread_runq *runq) * The thread is dispatched on a processor once again. * * Keep in mind the system state may have changed a lot since this - * function was called. In particular, the next thread may have been - * destroyed, and must not be referenced any more. + * function was called. In particular : + * - The next thread may have been destroyed, and must not be + * referenced any more. + * - The current thread may have been migrated to another processor. */ barrier(); - - /* The thread might have been moved to another processor */ + next = NULL; runq = thread_runq_local(); thread_runq_schedule_prepare(prev); + } else { + next = NULL; } assert(prev->preempt_level == THREAD_SUSPEND_PREEMPT_LEVEL); -- cgit v1.2.3