1 #include <stdio.h> 2 3 #include <uv.h> 4 hare(void * arg)5void hare(void *arg) { 6 int tracklen = *((int *) arg); 7 while (tracklen) { 8 tracklen--; 9 uv_sleep(1000); 10 fprintf(stderr, "Hare ran another step\n"); 11 } 12 fprintf(stderr, "Hare done running!\n"); 13 } 14 tortoise(void * arg)15void tortoise(void *arg) { 16 int tracklen = *((int *) arg); 17 while (tracklen) { 18 tracklen--; 19 fprintf(stderr, "Tortoise ran another step\n"); 20 uv_sleep(3000); 21 } 22 fprintf(stderr, "Tortoise done running!\n"); 23 } 24 main()25int main() { 26 int tracklen = 10; 27 uv_thread_t hare_id; 28 uv_thread_t tortoise_id; 29 uv_thread_create(&hare_id, hare, &tracklen); 30 uv_thread_create(&tortoise_id, tortoise, &tracklen); 31 32 uv_thread_join(&hare_id); 33 uv_thread_join(&tortoise_id); 34 return 0; 35 } 36