int main(int argc, char **argv) { printf("creating thread 1\n"); struct thread *t1 = thread_create(f1, NULL); thread_add_runqueue(t1); printf("creating thread 2\n"); struct thread *t2 = thread_create(f2, NULL); thread_add_runqueue(t2); printf("start threading\n"); thread_start_threading(); printf("exited\n"); return 0; }
void f1(void *arg) { int i = 100; struct thread *t2 = thread_create(f2, NULL); thread_add_runqueue(t2); struct thread *t3 = thread_create(f3, NULL); thread_add_runqueue(t3); while(1) { printf("thread 1: %d\n", i++); if (i == 110) { i = 100; } thread_yield(); } }
int main(int argc, char **argv) { struct thread *t1 = thread_create(f1, NULL); thread_add_runqueue(t1); thread_start_threading(); printf("\nexited\n"); return 0; }
void f1(void* arg){ printf("f1\n"); printf("creating thread 2 in f1\n"); struct thread *t2 = thread_create(f2, NULL); thread_add_runqueue(t2); printf("yielding in f1\n"); thread_yield(); printf("finishing f1 after yield\n"); }
void f3(void* arg){ printf("f3\n"); printf("creating thread 4 in f3\n"); struct thread *t4 = thread_create(f4, NULL); thread_add_runqueue(t4); printf("yielding in f3\n"); thread_yield(); printf("finishing f3 after yield\n"); }
void f2(void* arg){ printf("f2\n"); printf("creating thread 3 in f2\n"); struct thread *t3 = thread_create(f3, NULL); thread_add_runqueue(t3); printf("yielding in f2\n"); thread_yield(); printf("finishing f2 after yield\n"); //thread_exit(); }
void f2(void* arg){ printf("f2\n"); printf("f2 yield 1\n"); thread_yield(); printf("creating thread 4 for f3\n"); struct thread *t4 = thread_create(f3, NULL); thread_add_runqueue(t4); printf("f2 yield 2\n"); thread_yield(); printf("finishing f2\n"); thread_exit(); }
void f1(void* arg){ printf("f1\n"); printf("f1 yield 1\n"); thread_yield(); printf("f1 yield 2\n"); thread_yield(); printf("creating thread 3 for f3\n"); struct thread *t3 = thread_create(f3, NULL); thread_add_runqueue(t3); printf("f1 yield 3\n"); thread_yield(); printf("f1 yield 4\n"); thread_yield(); printf("finishing f1\n"); thread_exit(); }