From 6223846fdeabaa5028c0d06c1ac2fd69ea4b8911 Mon Sep 17 00:00:00 2001 From: sBubshait Date: Wed, 23 Oct 2024 16:30:38 +0100 Subject: [PATCH] Update lock_acquire to disable interrupts to eliminate race-conditions, w/ T --- src/threads/synch.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/threads/synch.c b/src/threads/synch.c index b99332e..7831774 100644 --- a/src/threads/synch.c +++ b/src/threads/synch.c @@ -248,15 +248,16 @@ lock_acquire (struct lock *lock) ASSERT (!lock_held_by_current_thread (lock)); struct thread *t = thread_current (); + enum intr_level old_level = intr_disable (); - /* 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; donate_priority (lock->holder); } + intr_set_level (old_level); + sema_down (&lock->semaphore); lock->holder = thread_current (); t->waiting_lock = NULL;