void
thread_set_priority (int new_priority) {
thread_current ()->init_priority = new_priority;
//현재 쓰레드의 우선 순위와 ready_list에서 가장 높은 우선 순위를 비교하여 스케줄링 하는 함수 호출
refresh_priority();
test_max_priority();
}
⭐️ 의문점
semaphore_elem 구조체와 semaphore 구조체의 차이
이때 semaphore 구조체와 semaphore_elem 구조체를 따로 정의 하는 이유
list_elem을 sysnch.c의 semaphore_elem이 아니라 synch.h의 semaphore 안에 선언하는 것이 나을 것이라 생각했지만, 토의 결과 그 의미가 다름을 깨달았다.
thread_init()에서 우선순위 값을 0으로 설정하는 것이 아닌 default(31)로 설정하는 이유
thread_init()에서 초기값으로 PRI_DEFAULT(31)로 선언하는데, 후에 idle thread에서 문제가 생길 것이라 생각했으나, thread_start()에서 idel thread의 priority를 PRI_MIN(0)으로 선언하여 문제는 없음을 확인했다.
허나 여전히 PRI_DEFAULT의 의미는 찾을 수 없었다.
리스트 정렬 한 값으로 사용 vs global_tick 사용
시간복잡도를 생각했을 때, 평균적으로 따지면 global_tick을 사용하는 것보다 sleep_list를 정렬해서 사용하는게 조금 더 나을 거라고 생각이 드는데 최악의 경우에서는 global_tick보다 정렬하는게 더 안좋기 때문에 코딩테스트 문제처럼 최악의 경우로 따져서 global_tick이 더 효율적인건가라는 의문점이 있음
sleep_list도 정렬하면 효율적이라 생각
Alarm Clock할 때 list.c에 list_insert_order라는 함수를 보고 sleep_list도 정렬해서 삽입하는게 더 효율적이지 않나 싶어서 생각해봄
🤔 회고
이번 주 일정은 조금씩 밀려버려서 extra부분은 이론적으로만 공부했다. 하지만 자력으로 구현한 alaram과 priority 일부는 정말 '나의 것'이 된 것처럼 이해할 수 있었고, 성취감도 컸다.
이에 우리 팀은 다음 주에는 더 빠듯하게 수행하여 extra까지 구현하는 것을 목표로 삼았다.
📝 전체 일정
✔ 최종 결과
🛠 Troubleshooting
cmp_sem_priority() vs cmp_priority()
cmp_sem_priority()
는 semaphore_elem에서 각 쓰레드 자체를 가져오고 그 스레드 내에 있는 priority 값을 가지고 온다.cmp_priority()
는 쓰레드 elem에서 priority를 가지고 온다.처음에는 쓰레드 elem에서 priority를 가지고 오면 된다고 생각했지만 semaphore를 적용하기 위해서는 thread가 아닌 semaphore_elem에 priority를 가지고 와야한다는 것을 깨닫고 cmp_sem_priority()를 구현했다.
thread_set_priority()
thread의 우선순위를 갱신해 줄 때 가장 높은 우선 순위로 변경하는 로직을 적용했어야 했는데 현재 실행되고 있는 스레드의 우선순위를 저장했다.
그래서 test code에서 우선순위가 가장 높은 우선순위로 변경되지 않는 오류가 발생했다.
⭐️ 의문점
semaphore_elem 구조체와 semaphore 구조체의 차이
이때 semaphore 구조체와 semaphore_elem 구조체를 따로 정의 하는 이유 list_elem을 sysnch.c의 semaphore_elem이 아니라 synch.h의 semaphore 안에 선언하는 것이 나을 것이라 생각했지만, 토의 결과 그 의미가 다름을 깨달았다.
thread_init()에서 우선순위 값을 0으로 설정하는 것이 아닌 default(31)로 설정하는 이유
thread_init()에서 초기값으로 PRI_DEFAULT(31)로 선언하는데, 후에 idle thread에서 문제가 생길 것이라 생각했으나, thread_start()에서 idel thread의 priority를 PRI_MIN(0)으로 선언하여 문제는 없음을 확인했다. 허나 여전히 PRI_DEFAULT의 의미는 찾을 수 없었다.
리스트 정렬 한 값으로 사용 vs global_tick 사용
sleep_list도 정렬하면 효율적이라 생각
🤔 회고
이번 주 일정은 조금씩 밀려버려서 extra부분은 이론적으로만 공부했다. 하지만 자력으로 구현한 alaram과 priority 일부는 정말 '나의 것'이 된 것처럼 이해할 수 있었고, 성취감도 컸다. 이에 우리 팀은 다음 주에는 더 빠듯하게 수행하여 extra까지 구현하는 것을 목표로 삼았다.