핀토스
새로 수정한 점
void thread_sleep(int64_t ticks)
{
enum intr_level old_level;
struct thread *curr = thread_current();
old_level = intr_disable();
curr->wake_time = timer_ticks() + ticks;
list_insert_ordered(&sleep_list, &curr->elem, compare_thread, NULL);
thread_block();
intr_set_level(old_level);
}
void thread_wake(void)
{
int64_t current_ticks = timer_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->wake_time <= current_ticks)
{
e = list_remove(e);
thread_unblock(t);
}
else
{
break;
}
}
}
- 지금까지 했던 방법은 timer.c 에 있는
timer_sleep(), timer_interrupt() 에 직접 코드를 때려박아 재우기 깨우기를 했는데, 이런 방식을 사용한다면 thread.c 와 timer.c 에서 쓰이는 슬립리스트가 달라질 수 있기에, 리스트가 선언된 thread.c 에서 함수를 만들기로 했다.
- 민석왈 디버깅하기에도 이방법이 좋다고 한다.
list_insert_ordered(&sleep_list, &curr->elem, compare_thread, NULL); // 리스트에 넣어주기 -> 지금까진 뒤에 계속 넣어줬는데, 이 방법을 쓰면 테스트 몇개 실패함. 순서대로 넣어주면 테스트 모두 성공.