Update lock_acquire to disable interrupts to eliminate race-conditions, w/ T
This commit is contained in:
@@ -248,15 +248,16 @@ lock_acquire (struct lock *lock)
|
|||||||
ASSERT (!lock_held_by_current_thread (lock));
|
ASSERT (!lock_held_by_current_thread (lock));
|
||||||
|
|
||||||
struct thread *t = thread_current ();
|
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)
|
if (lock->holder != NULL)
|
||||||
{
|
{
|
||||||
t->waiting_lock = lock;
|
t->waiting_lock = lock;
|
||||||
donate_priority (lock->holder);
|
donate_priority (lock->holder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
intr_set_level (old_level);
|
||||||
|
|
||||||
sema_down (&lock->semaphore);
|
sema_down (&lock->semaphore);
|
||||||
lock->holder = thread_current ();
|
lock->holder = thread_current ();
|
||||||
t->waiting_lock = NULL;
|
t->waiting_lock = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user