ํ์ฌ ํํ ์ค์์๋ ์ค๋ ๋๋ฅผ ์ฐ์ ์์์ ์๊ด์์ด ์คํํ๊ณ ์๋ค. ์ด ๊ณผ์ ์ ๋ชฉํ๋ ์ฐ์ ์์ ์์๋๋ก ์ค๋ ๋๊ฐ ์คํ๋๋๋ก ํ๋ ๊ฒ!
CPU๋ ready_list์ ์๋ ์ค๋ ๋๋ฅผ ์์๋๋ก ์คํํ๋ค. ํ์ฌ ํํ ์ค์์๋ ready_list์ ์ค๋ ๋๋ฅผ ์ถ๊ฐํ  ๋ ๋ฆฌ์คํธ์์ ์ฐ์ ์์์ ๋ง๊ฒ ์ฝ์
ํ๋ ๊ฒ์ด ์๋๋ผ ๋จ์ํ ์ ์ผ ๋ค์ ์ถ๊ฐํ๊ณ  ์๋ค. (ํ์ฌ๋ list_push_back์ธ๋ฐ, list_insert_ordered๋ก ๋ฐ๊ฟ๊ฒ์)
void
list_insert_ordered (struct list *list, struct list_elem *elem,
		list_less_func *less, void *aux) {
	struct list_elem *e;
	ASSERT (list != NULL);
	ASSERT (elem != NULL);
	ASSERT (less != NULL);
	for (e = list_begin (list); e != list_end (list); e = list_next (e))
		if (less (elem, e, aux))
			break;
	return list_insert (e, elem);
}์์ ์ฝ๋์์ ํจ์์ ์ธ์ ๋ถ๋ถ์ list_less_func *less, void *aux๋ฅผ ๋ณด์.
์ด๋ list_insert_orderedํจ์์์ less๋ผ๋ ํจ์๋ฅผ ์ฌ์ฉํ  ๊ฒ์ด๊ณ , less์ ์ธ์๋ก๋ aux๋ฅผ ์ฌ์ฉํ๋ค๋ ์๋ฏธ์ด๋ค.
์๋ ์ฝ๋์ ๊ฐ์ด ์ฌ์ฉํ ์ ์๋ค.
list_insert_ordered(&ready_list, &t->elem, cmp_priority, NULL);์ด ๋ฌธ์ ๋ ready_list์ thread๋ฅผ ์ฝ์
ํ  ๋ ์ฐ์ ์์๊ฐ ์ ๋ ฌ๋๋๋ก ์ฝ์
ํ๋๋ก ์์ ํด์ ํด๊ฒฐํ์. (list_insert_ordered ํจ์์ ์ธ์๋ก cmp_priority๋ผ๋ ์ฐ์ ์์ ๋น๊ต ํจ์๋ฅผ ๋ฃ์ด์ฃผ์)
ํ์ฌ CPU๋ฅผ ์ ์ ํ๊ณ  ์๋ ์ค๋ ๋์ ์ฐ์ ์์๊ฐ ready_list์์ ์ฐ์ ์์๊ฐ ๊ฐ์ฅ ๋์ ์ค๋ ๋๋ณด๋ค ์ฐ์ ์์๋ณด๋ค ๋ฎ์ผ๋ฉด ์ด ์ค๋ ๋๊ฐ CPU๋ฅผ ์ ์ ํ  ์ ์๋๋ก ํด์ผํ๋ค. (thread_yield)
ready_list์ ์ค๋ ๋๊ฐ ์ฐ์ ์์๋๋ก ์ ๋ ฌ๋๋๋ก ํ๊ธฐ ์ํด, ์ค๋ ๋๋ฅผ ์ถ๊ฐํ  ๋ ํํ ์ค ๋ด์ฅ๋ ํจ์์ธ list_insert_ordered ํจ์๋ฅผ ์ฌ์ฉํ๋ค. ์ด๋ ์ฌ์ฉํ  ์ฐ์ ์์ ๋น๊ตํจ์ cmp_priority๋ฅผ ๋ง๋ค์ด์ค๋ค.
์ด์  thread๊ฐ unblock ๋  ๋ ์ฐ์ ์์๋๋ก ์ ๋ ฌ๋์ด ready_list์ ์ค๋ ๋๊ฐ ์ถ๊ฐ๋  ์ ์๋๋ก, thread_unblockํจ์์์ list_push_back์ list_insert_orderd๋ก ๋ฐ๊ฟ์ค๋ค.
ํ์ฌ CPU์ ์  ์ค์ธ ์ค๋ ๋๊ฐ CPU ์ ์ ๋ฅผ ์๋ณดํ๊ณ  ready_list์ ์ค๋ ๋๋ฅผ ์ถ๊ฐํ  ๋ ์ฌ์ฉํ๋ ํจ์์ธ thread_yield()์ ๋ด๋ถ์์ ready_list์ ์ฝ์
๋๋ ๋ถ๋ถ์ list_push_back์ list_insert_orderd๋ก ๊ต์ฒดํ๋ค.
ready_list์ ์ฒซ๋ฒ์งธ ์ค๋ ๋๊ฐ CPU ์ ์  ์ค์ธ ์ค๋ ๋๋ณด๋ค ์ฐ์ ์์๊ฐ ๋์ผ๋ฉด CPU์ ์ ๋ฅผ ์๋ณดํ๋ ํจ์ test_max_priorityํจ์๋ฅผ ๋ง๋ ๋ค. (thread_yield ์ด์ฉ)
๋ณธ ๊ณผ์ ๋ list_push_back์ผ๋ก ๊ตฌํ๋ ๋ถ๋ถ์ list_insert_ordered์ cmp_priority๋ฅผ ์ด์ฉํด์ ๊ณ ์ณ์ฃผ๋ฉด ์ฝ๊ฒ ํด๊ฒฐํ  ์ ์์๋ค.
thread ๊ตฌ์กฐ์ฒด๋ ๋ชจ๋ list, list_elem์ผ๋ก ์ฐ๊ฒฐ๋์ด ์๊ธฐ ๋๋ฌธ์, list ๊ตฌ์กฐ์ฒด์์ ์ ๊ณตํ๋ ํจ์๋ฅผ ์ ์ฌ์ฉํ๋ฉด ํธํ๊ฒ ๊ตฌํํ  ์ ์๋ค. ๊ทธ๋ฅ ๊ฐ์ ธ๋ค์ฐ์ง๋ง๊ณ  ํญ์ ๊ทธ ํจ์์ ์ธ์, ๊ตฌ์กฐ, ์๋์๋ฆฌ๋ฅผ ํ์
ํ๊ณ  ์ฌ์ฉํ๋ ์ต๊ด์ ๋ค์ด์!