Update set priority to eliminate race condition when accessing ready list
This commit is contained in:
@@ -389,6 +389,8 @@ thread_set_priority (int new_priority)
|
|||||||
|
|
||||||
thread_current ()->priority = new_priority;
|
thread_current ()->priority = new_priority;
|
||||||
|
|
||||||
|
enum intr_level old_level = intr_disable ();
|
||||||
|
|
||||||
if (new_priority < old_priority && !list_empty (&ready_list)) {
|
if (new_priority < old_priority && !list_empty (&ready_list)) {
|
||||||
/* If the new priority is lower than the old priority, check if the current
|
/* If the new priority is lower than the old priority, check if the current
|
||||||
thread no longer has the highest priority. If it doesn't, yield the CPU.
|
thread no longer has the highest priority. If it doesn't, yield the CPU.
|
||||||
@@ -401,6 +403,8 @@ thread_set_priority (int new_priority)
|
|||||||
thread_yield();
|
thread_yield();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
intr_set_level (old_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the current thread's priority. */
|
/* Returns the current thread's priority. */
|
||||||
|
|||||||
Reference in New Issue
Block a user