3

thread.c 中的 Schedule() 获取当前正在运行的线程和就绪列表中的下一个线程,并断言下一个线程是线程(is_thread(t) 检查 t != NULL 和 t->magic = = 线程魔法)。我目前收到此错误:

Kernel PANIC at ../../threads/thread.c:563 in schedule(): assertion 'is_thread(next)' failed.

我目前正在实施 timer_sleep 以便它不会忙于等待。这是我的 timer_sleep 函数:

void
timer_sleep (int64_t ticks) 
{
  if (ticks > 0)
  {
    ASSERT (intr_get_level () == INTR_ON);
    enum intr_level old_level;
    old_level = intr_disable ();

    struct thread *current_thread;
    current_thread = thread_current();

    int64_t wake_tick = timer_ticks() + ticks;
    current_thread->wake_tick = wake_tick;

    list_insert_ordered (&sleep_list, &current_thread->timer_elem, cmp_wake_ticks, NULL);
    thread_block();

    intr_set_level(old_level);
  }
}

还有我的 timer_interrupt:

static void
timer_interrupt (struct intr_frame *args UNUSED)
{
  enum intr_level old_level;
  old_level = intr_disable ();

  ticks++;
  thread_tick ();

  struct list_elem* sl_elem;
  struct thread* sl_thread;
  while(!list_empty(&sleep_list))
  {
    sl_elem = list_front(&sleep_list);
    sl_thread = list_entry(sl_elem, struct thread, timer_elem);

    if (sl_thread->wake_tick > ticks)
    {
      break;
    }

    thread_unblock(sl_thread);
    list_remove(sl_elem);
  }

  intr_set_level (old_level);
}

将任何东西添加到 ready_list 的唯一地方是 thread_unblock,它也执行 ASSERT is_thread,所以我不确定哪些不是线程的东西会被添加到就绪列表中。除了将 timer_elem 添加到 thread.h 和线程 cmp_wake_ticks 函数之外,我没有对基本代码进行任何其他更改。

4

0 回答 0