alarm-priority ν
μ€νΈ ν΅κ³Ό
μ¬λ¬ μ€λ λκ° λμΌν μκ°μ κΉ¨μ΄λ λ, μ°μ μμ(priority)κ° λμ μ€λ λκ° λ¨Όμ μ€νλλλ‘ λ³΄μ₯ν΄μΌ ν¨
μ²μμλ alarm-priority ν
μ€νΈκ° λ€μκ³Ό κ°μ μ΄μ λ‘ μ€ν¨ν¨:
ready_listμ μ€λ λλ₯Ό μ½μ
ν λ μ°μ μμ μ λ ¬(priority ordering) μ μ μ©νμ§ μμthread_unblock() ν¨μκ° νμ 리μ€νΈ 맨 λ€μ push (FIFO μ½μ
)thread_unblock() μμ π μμΉ: threads/thread.c
// μμ μ
list_push_back(&ready_list, &t->elem);
// μμ ν
list_insert_ordered(&ready_list, &t->elem, priority_cmp, NULL);
β priority_cmpλ₯Ό κΈ°μ€μΌλ‘ ready_listλ₯Ό μ λ ¬νλλ‘ λ³κ²½
priority_cmp() ν¨μ ꡬνπ μμΉ: threads/thread.c
bool priority_cmp(const struct list_elem *a, const struct list_elem *b, void *aux UNUSED) {
struct thread *a_thread = list_entry(a, struct thread, elem);
struct thread *b_thread = list_entry(b, struct thread, elem);
return a_thread->priority > b_thread->priority;
}
β μ«μκ° ν΄μλ‘ λμ priorityμ΄λ―λ‘ > λΉκ΅λ₯Ό μ¬μ©
priority_cmp() μ μΈ μΆκ°π μμΉ: threads/thread.h
bool priority_cmp(const struct list_elem *a, const struct list_elem *b, void *aux);
β C μΈμ΄μμλ ν¨μ μ μ μ μ μ μΈ(prototype)μ΄ νμνλ―λ‘ ν€λμ μ μΈν΄μ€
make clean && make check
pass tests/threads/alarm-priority β
ready_listλ λ¨μ νκ° μλλΌ priority-aware ν΄μΌ νλ€list_insert_ordered() + priority_cmp()λ νμ