Hacker News new | past | comments | ask | show | jobs | submit login

The code that uses it is pretty complex (go up two folders in my gitlab link for that), so here's a minimal example of the full API:

  cothread_t a, b;  //cothread_t is a typedef to void*
  int main() {
    a = co_active();  //get a handle to the main thread
    b = co_create(entrypoint, stacksize_in_bytes);
    printf("a");
    co_switch(b);
    printf("c");
    co_delete(b);  //no need to delete a
  }
  void entrypoint() {
    printf("b");
    co_switch(a);
  }
  //output: "abc"
We've only been using it in emulators so far. It's in MESS, higan, twoMbit and a few others.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: