From 471a5da32d4b41a71ef74dbca46fd88493ad0948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 16 Feb 2021 10:47:53 +0100 Subject: disable interrupts when queueing threads --- src/devices/timer.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/devices/timer.c') diff --git a/src/devices/timer.c b/src/devices/timer.c index 856a14e..aea6aa2 100644 --- a/src/devices/timer.c +++ b/src/devices/timer.c @@ -114,6 +114,9 @@ timer_sleep (int64_t ticks) new_waiting_thread.tick_target = start + ticks; sema_init (&new_waiting_thread.sema, 0); + // disable interrupts so the timer interrupt handler can't modify the list + enum intr_level old_level = intr_disable (); + struct list_elem *before = list_begin (&waiting_threads); while (before != list_end (&waiting_threads)) { struct list_elem *next = list_next (before); @@ -125,6 +128,8 @@ timer_sleep (int64_t ticks) } list_insert (before, &new_waiting_thread.elem); + intr_set_level (old_level); + sema_down (&new_waiting_thread.sema); } -- cgit v1.2.1