Blue-club / pintos_6

Other
0 stars 3 forks source link

[WIL] 회고 & 의문점 #8

Open heekyoung2000 opened 1 year ago

heekyoung2000 commented 1 year ago

📝 전체 일정

✔ 최종 결과

image

🛠 Troubleshooting

image

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()를 구현했다.

//cmp_priority()
bool cmp_priority(const struct list_elem *a,const struct list_elem *b, void *aux UNUSED){
    /*첫번째 인자의 우선순위가 높으면 1을 반환, 두번째 인자의 우선순위가 높으면 0을 반환*/

    struct thread *t_a = list_entry(a, struct thread, elem);
    struct thread *t_b = list_entry(b, struct thread, elem);

    if (t_a -> priority > t_b ->priority) return 1;
    else return 0; 
}
//cmp_sem_priority()
bool cmp_sem_priority(const struct list_elem *a,const struct list_elem *b, void *aux UNUSED){

    struct semaphore_elem * sa = list_entry(a,struct semaphore_elem,elem);
    struct semaphore_elem * sb = list_entry(b,struct semaphore_elem,elem);

    struct list_elem *sa_e = list_begin(&(sa->semaphore.waiters));
    struct list_elem *sb_e = list_begin(&(sb->semaphore.waiters));

    struct thread *t_a = list_entry(sa_e, struct thread, elem);
    struct thread *t_b = list_entry(sb_e, struct thread, elem);

    return (t_a -> priority > t_b ->priority);
}

thread_set_priority()

thread의 우선순위를 갱신해 줄 때 가장 높은 우선 순위로 변경하는 로직을 적용했어야 했는데 현재 실행되고 있는 스레드의 우선순위를 저장했다.
그래서 test code에서 우선순위가 가장 높은 우선순위로 변경되지 않는 오류가 발생했다.

//오류코드
void
thread_set_priority (int new_priority) {
    thread_current ()->priority = new_priority;
    test_max_priority();
void
thread_set_priority (int new_priority) {
    thread_current ()->init_priority = new_priority;
    //현재 쓰레드의 우선 순위와 ready_list에서 가장 높은 우선 순위를 비교하여 스케줄링 하는 함수 호출
    refresh_priority();
    test_max_priority();
}

⭐️ 의문점

semaphore_elem 구조체와 semaphore 구조체의 차이

IMG_CC2798943F1E-1

리스트 정렬 한 값으로 사용 vs global_tick 사용

sleep_list도 정렬하면 효율적이라 생각

🤔 회고

이번 주 일정은 조금씩 밀려버려서 extra부분은 이론적으로만 공부했다. 하지만 자력으로 구현한 alaram과 priority 일부는 정말 '나의 것'이 된 것처럼 이해할 수 있었고, 성취감도 컸다. 이에 우리 팀은 다음 주에는 더 빠듯하게 수행하여 extra까지 구현하는 것을 목표로 삼았다.