Now I changed the code to a much simpler one, that simplifies the problem. Whenever I pause with the debugger and p goredump()
this is the result.
COROUTINE state current created
------------------------------------------------------------------------------------------------------------------------
{0} msleep() /Users/paulofaria/test.c:12 <main>
{1} RUNNING --- /Users/paulofaria/test.c:11
I tried it in my Linux virtual machine and the same happens. msleep()
never returns.
Doing some more debugging I found out that mill_wait()
is never reached from mill_suspend()
after we call msleep()
because !mill_slist_empty(&mill_ready)
returns true.
int mill_suspend(void) {
if(mill_running && mill_setjmp(&mill_running->ctx))
return mill_running->result;
while(1) {
if(!mill_slist_empty(&mill_ready)) {
// Runs this
struct mill_slist_item *it = mill_slist_pop(&mill_ready);
mill_running = mill_cont(it, struct mill_cr, u_ready.item);
mill_jmp(&mill_running->ctx);
}
// Never runs this
mill_wait();
assert(!mill_slist_empty(&mill_ready));
}
}
Another thing i noticed is that mill_go_epilogue();
is never called because the routine runs in an infinite loop. Is this related to !mill_slist_empty(&mill_ready)
returning true?