From 1f01a561a36caee80202a8d10031a9046083cd46 Mon Sep 17 00:00:00 2001 From: ChUrl Date: Mon, 4 Jul 2022 14:54:25 +0200 Subject: [PATCH] fix scheduling bug when only 1 thread is available --- c_os/kernel/threads/Scheduler.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/c_os/kernel/threads/Scheduler.cc b/c_os/kernel/threads/Scheduler.cc index 35af795..dead80a 100644 --- a/c_os/kernel/threads/Scheduler.cc +++ b/c_os/kernel/threads/Scheduler.cc @@ -96,10 +96,12 @@ void Scheduler::yield() { /* hier muss Code eingefuegt werden */ - // if (this->readyQueue.isEmpty()) { - // // Idle thread running - // return; - // } + // When only one thread exists (IdleThread) it can't yield as the readyqueue becomes empty + // and this is not handled anywhere else + if (this->readyQueue.isEmpty()) { + // Idle thread running + return; + } Thread& next = *(Thread*)this->readyQueue.dequeue(); this->readyQueue.enqueue(this->get_active());