Updated set priority to yield if priority is lowered

This commit is contained in:
sBubshait
2024-10-17 06:27:59 +01:00
parent 9f53040d27
commit 5c09ff0149

View File

@@ -388,6 +388,19 @@ thread_set_priority (int new_priority)
return; return;
thread_current ()->priority = new_priority; thread_current ()->priority = new_priority;
if (new_priority < old_priority && !list_empty (&ready_list)) {
/* If the new priority is lower than the old priority, check if the current
thread no longer has the highest priority. If it doesn't, yield the CPU.
*/
struct thread *next_thread =
list_entry (list_front (&ready_list), struct thread, elem);
if (next_thread->priority > new_priority) {
thread_yield();
}
}
} }
/* Returns the current thread's priority. */ /* Returns the current thread's priority. */