Alarm Clock은 가이드에 굉장히 친절하게 나와있다. 그대로만 따라하면 90퍼는 완성!
테스트 케이스를 참고해서 예외 상황 처리해주면 된다.
가이드에 정독하라는 파일들은 주석 꼼꼼히 읽어야 실수 안하고 테스트 통과할 수 있습니다!
void timer_sleep(int64_t ticks)
{
if (ticks <= 0)
return;
struct thread *curr = thread_current();
int64_t wakeup_tick = timer_ticks() + ticks;
curr->wakeup_tick = wakeup_tick;
enum intr_level old_level;
old_level = intr_disable();
list_push_back(&sleep_list, &(curr->elem));
thread_block();
intr_set_level(old_level);
ASSERT(intr_get_level() == INTR_ON);
}
static void timer_interrupt(struct intr_frame *args UNUSED)
{
ticks++;
struct list_elem *e = list_begin (&sleep_list);
while (e != list_end (&sleep_list))
{
struct thread *t = list_entry (e, struct thread, elem);
if (t->wakeup_tick <= ticks) {
e = list_remove (e);
thread_unblock (t);
} else {
e = list_next (e);
}
}
thread_tick();
}
쓰레드 struct에 int64_t wakeup_tick 처리 및 timer.c에서 sleep_list 선언 및 초기화 잊지말기!
