diff --git a/src/threads/synch.c b/src/threads/synch.c index cdfb2dc..b74303d 100644 --- a/src/threads/synch.c +++ b/src/threads/synch.c @@ -68,8 +68,7 @@ sema_down (struct semaphore *sema) old_level = intr_disable (); while (sema->value == 0) { - list_insert_ordered(&sema->waiters, &thread_current ()->elem, - priority_more, NULL); + list_push_back (&sema->waiters, &thread_current ()->elem); thread_block (); } sema->value--; @@ -114,9 +113,12 @@ sema_up (struct semaphore *sema) ASSERT (sema != NULL); old_level = intr_disable (); - if (!list_empty (&sema->waiters)) - thread_unblock (list_entry (list_pop_front (&sema->waiters), - struct thread, elem)); + if (!list_empty (&sema->waiters)) + { + struct list_elem *e = list_min (&sema->waiters, priority_more, NULL); + list_remove (e); + thread_unblock (list_entry (e, struct thread, elem)); + } sema->value++; intr_set_level (old_level);