Last active
August 16, 2018 07:16
-
-
Save liuliu/ecd8d1fd2a0238674085325427ddf4c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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