오늘까지 alarm-test 6개 + priority-change,fifo,preempt까지 통과 했음.
// thread.c
// 쓰레드와 현재 list 의 값들 하나하나 비교 하는 함수
static bool compare_thread(const struct list_elem *a, const struct list_elem *b, void *aux UNUSED)
{
struct thread *sa = list_entry(a, struct thread, elem);
struct thread *sb = list_entry(b, struct thread, elem);
return sa->priority > sb->priority;
}
// thread.c
void thread_set_priority(int new_priority)
{
thread_current()->priority = new_priority;
// 추가된 부분
if (thread_current()->priority < list_entry(list_begin(&ready_list), struct thread, elem)->priority)
{
thread_yield();
}
}
tid_t thread_create(const char *name, int priority,
thread_func *function, void *aux)
{
....
// 추가
// list_insert_ordered(&ready_list, &t->elem, compare_thread, NULL);
// t->status = THREAD_READY;
if (t->priority > thread_current()->priority)
{
thread_yield();
}
}
- 우선순위가 변경되거나 새로운 스레드가 만들어져 우선순위를 새로 비교해야하는 상황이 왔을 때 필요한 코드