Skip to content

Instantly share code, notes, and snippets.

@liuliu
Last active August 16, 2018 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liuliu/ecd8d1fd2a0238674085325427ddf4c0 to your computer and use it in GitHub Desktop.
Save liuliu/ecd8d1fd2a0238674085325427ddf4c0 to your computer and use it in GitHub Desktop.
static void g(task_t* const task)
{
printf("start task %p\n", task);
taskyield(task);
printf("back to task %p to finish\n", task);
}
static void f(task_t* const task)
{
printf("create a new task to resume %p\n", task);
task_t* gtask = taskcreate(task->schd, g);
taskresume(gtask); // Run the gtask directly.
printf("done task %p\n", task);
}
int main(void)
{
schd_t schd = {};
pthread_cond_init(&schd.cv, 0);
pthread_mutex_init(&schd.mutex, 0);
task_t* task = taskcreate(&schd, f);
addtask(&schd, task);
schdmain(&schd);
pthread_cond_destroy(&schd.cv);
pthread_mutex_destroy(&schd.mutex);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment