我一直在做pintos项目,优先级调度。 使用优先级捐赠,错误消息断言:is_interior(before)|| is_tail(之前),继续发生。
我试图解决此问题(我也放置了代码“ list_init(%t-> holding_lock_list)”,因为“断言失败”发生在“ is_interior”或“ is_tail”中),但是它没有用。
我该如何解决?
struct thread{
...
int original_priority;
struct lock * wanting_lock;
struct list holding_lock_list;
}
tid_t thread_create(...){
...
list_init(&t->holding_lock_list);
}
struct lock{
struct thread *holder;
struct semaphore semaphore;
struct list_elem elem;
}
//---------------------------------------------------------------
void priority_donation(struct lock *lock){
struct thread *owner = &lock->holder;
if(owner != NULL){
struct thread * cur = thread_current();
if(cur->priority > owner->priority){
owner->original_priority = owner->priority;
owner->priority = cur->priority;
if(owner->wanting_lock != NULL)
priority_donation(owner->wanting_lock);
}
}
}
void priority_reduction(struct lock *lock){
struct thread *cur = thread_current();
struct lock *next_lock=list_entry(list_front(&cur->holding_lock_list),struct thread, elem);
if(next->lock != NULL && !list_empty(&next_lock->semaphore.waiters))
{
struct thread * next_lock_t = list_entry(list_front(&next_lock->semaphore.waiters),struct thread,elem);
if(next_lock_t->priority > cur->original_priority && next_lock_t->priority == cur->priority)
return;
else{
cur->priority = cur->original_priority;
return;
}
}
cur->priority = cur->original_priority;
}
//----------------------------------------------------------------
void lock_acquire(struct lock *lock)
{
...
struct thread *cur = thread_current();
priority_donation(lock);
cur->wanting_lock = lock;
sema_down(&lock->semaphore);
cur->wanting_lock = NULL;
lock->holder = thread_current();
list_push_front(&thread_current()->holding_lock_list,&lock_elem);
}
void lock_release(struct lock *lock)
{
...
list_pop_front(&thread_current()->holding_lock_list);
priority_reduction(lock);
...
}