Skip to content

Instantly share code, notes, and snippets.

@paulofaria
Last active August 29, 2015 14:27
Show Gist options
  • Save paulofaria/6a5ce702e0d05dc89a76 to your computer and use it in GitHub Desktop.
Save paulofaria/6a5ce702e0d05dc89a76 to your computer and use it in GitHub Desktop.
libmill

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?

#include "libmill.h"
void loop() {
while (1) {
yield();
}
}
void main() {
go(loop());
msleep(now() + 1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment