Schedule() in thread.c takes the current running thread and the next thread in the ready list, and does an ASSERT that the next thread is a thread (is_thread(t) checks that t != NULL and that t->magic == THREAD_MAGIC). I'm currently getting this error:
Kernel PANIC at ../../threads/thread.c:563 in schedule(): assertion 'is_thread(next)' failed.
I'm currently implementing timer_sleep so that it doesn't do busy waiting. Here is my timer_sleep function:
void
timer_sleep (int64_t ticks)
{
if (ticks > 0)
{
ASSERT (intr_get_level () == INTR_ON);
enum intr_level old_level;
old_level = intr_disable ();
struct thread *current_thread;
current_thread = thread_current();
int64_t wake_tick = timer_ticks() + ticks;
current_thread->wake_tick = wake_tick;
list_insert_ordered (&sleep_list, ¤t_thread->timer_elem, cmp_wake_ticks, NULL);
thread_block();
intr_set_level(old_level);
}
}
And my timer_interrupt:
static void
timer_interrupt (struct intr_frame *args UNUSED)
{
enum intr_level old_level;
old_level = intr_disable ();
ticks++;
thread_tick ();
struct list_elem* sl_elem;
struct thread* sl_thread;
while(!list_empty(&sleep_list))
{
sl_elem = list_front(&sleep_list);
sl_thread = list_entry(sl_elem, struct thread, timer_elem);
if (sl_thread->wake_tick > ticks)
{
break;
}
thread_unblock(sl_thread);
list_remove(sl_elem);
}
intr_set_level (old_level);
}
The only place where anything is being added to the ready_list is in thread_unblock, which also does an ASSERT is_thread, so I'm not sure where something that isn't a thread would ever be added to the ready list. I've not made any other changes to the base code other than adding the timer_elem to thread.h and the thread cmp_wake_ticks function.
In
list_insert_ordered()
, you usestruct elem
"timer_elem"But see
next_thread_run()
function(call byis_thread()
)Implement like this
That means, blocked thread in ready_list use "timer_elem" but pop function use "elem"
So you unify your
stuct elem
to "elem"