From 163b7f9016162f976090c172f9dba655b0f54aaa Mon Sep 17 00:00:00 2001 From: Themis Demetriades Date: Tue, 15 Oct 2024 15:38:31 +0100 Subject: [PATCH] Update setting of priority of threads to only yield when current thread's priority has been lowered --- src/threads/thread.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/threads/thread.c b/src/threads/thread.c index 6c1dcca..3a428f1 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -357,8 +357,11 @@ void thread_set_priority (int new_priority) { ASSERT (PRI_MIN <= new_priority && new_priority <= PRI_MAX); + int old_priority = thread_get_priority (); + thread_current ()->priority = new_priority; - thread_yield (); + if (new_priority < old_priority) + thread_yield (); } /* Returns the current thread's priority. */