From 30ab3ae8616ad46cf1d9c142d938ed1a2e8b96fa Mon Sep 17 00:00:00 2001 From: sBubshait Date: Fri, 25 Oct 2024 15:47:19 +0100 Subject: [PATCH] Update thread_create to only yield CPU to the new thread if necessary --- src/threads/thread.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/threads/thread.c b/src/threads/thread.c index 9e2fa41..d488677 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -261,7 +261,11 @@ thread_create (const char *name, int priority, /* Add to run queue. */ thread_unblock (t); - thread_yield (); + + /* Yield if the newly created thread has higher priority than the current + thread. */ + if (t->priority > thread_current ()->priority) + thread_yield (); return tid; }