From f98e4bc81c70ee4e0ec90536d9f02329ff702210 Mon Sep 17 00:00:00 2001 From: Themis Demetriades Date: Sun, 20 Oct 2024 19:19:43 +0100 Subject: [PATCH] Update lock_acquire to attempt donation of priorities, w/ S --- src/threads/synch.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/threads/synch.c b/src/threads/synch.c index d773824..4bf54a6 100644 --- a/src/threads/synch.c +++ b/src/threads/synch.c @@ -187,6 +187,9 @@ lock_init (struct lock *lock) sema_init (&lock->semaphore, 1); } +static void +donate_priority (struct thread *donor, struct thread *donee); + /* Acquires LOCK, sleeping until it becomes available if necessary. The lock must not already be held by the current thread. @@ -202,8 +205,18 @@ lock_acquire (struct lock *lock) ASSERT (!intr_context ()); ASSERT (!lock_held_by_current_thread (lock)); + struct thread *t = thread_current (); + + /* TODO: If a high-priority thread holding a lock sleeps, this may cause a + race condition here or break the assumption that donation must occur. */ + if (lock->holder != NULL) + { + t->waiting_lock = lock; + } + sema_down (&lock->semaphore); lock->holder = thread_current (); + t->waiting_lock = NULL; } /* Tries to acquires LOCK and returns true if successful or false