Pintos Project1 day 5

John Jean·2024년 8월 27일

pintos

목록 보기
5/7

Pintos

진행상황

오늘까지 alarm-test 6개 + priority-change,fifo,preempt까지 통과 했음.

  • alarm에서는 스레드의 활성화 & 비활성화에 집중된 과제를 했다면, priority에서는 각 스레드의 우선순위에따라 새로 스케쥴링을 하는 과제를 수행하게 됨.

추가, 수정한 코드

compre_thread()

// 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_set_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();
	}
}

thread_create()

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();
	}
}
  • 우선순위가 변경되거나 새로운 스레드가 만들어져 우선순위를 새로 비교해야하는 상황이 왔을 때 필요한 코드
profile
크래프톤 6기 정글러

0개의 댓글