timer_sleep() 고쳐보기.// timer.c
void timer_sleep(int64_t ticks)
{
// int64_t start = timer_ticks();
// ASSERT(intr_get_level() == INTR_ON);
// while (timer_elapsed(start) < ticks)
// thread_yield();
int64_t start = timer_ticks();
struct thread *curr = thread_current();
// 기상시간 정해주기
curr->wake_time = start + ticks;
// 일단 리스트 뒤에 넣어주자.
list_push_back(&sleep_list, &curr->elem);
// 이제 재우자
thread_block();
ASSERT(intr_get_level() == INTR_ON);
// while을 지울거임.
// while (timer_elapsed(start) < ticks)
// thread_yield();
}
// thread.h
// 수면리스트 생성
struct list sleep_list;
// 이런식으로 만들어줘도 되나..
- 전역 리스트를 사용하려면 시스템 초기화 시점에 반드시 초기화해줘야 합니다. 이는 보통 thread_init() 함수에서 수행됩니다.
라고 하니 thread_init에서 초기화 해주면 될듯.
// thread.c
void thread_init(void)
{
ASSERT(intr_get_level() == INTR_OFF);
/* Reload the temporal gdt for the kernel
* This gdt does not include the user context.
* The kernel will rebuild the gdt with user context, in gdt_init (). */
struct desc_ptr gdt_ds = {
.size = sizeof(gdt) - 1,
.address = (uint64_t)gdt};
lgdt(&gdt_ds);
/* Init the globla thread context */
lock_init(&tid_lock);
list_init(&ready_list);
list_init(&destruction_req);
// 슬립 리스트 초기화. 스레드 이닛은 보통 한 번만 실행된다는데 함 봐야 알듯.
list_init(&sleep_list);
// 현재 틱 마다 기상시켜야 할 스레드가 있는지 체크하고 불침번이 깨워주는 함수 만들기.
// 매 틱마다 실행되는 함수가 분명히 있을거같음. 찾아보자.
thread_ticks = 0; -> 타임슬라이스 초기화
timer_ticks (void) -> 부팅되고나서 지난 시간 반환
스레드 구조체에 변수를 추가하면, 스레드를 만들 때 초기화를 해줘야 하나?