/* hello.c -- compile with "gcc -Wall hello.c -o hello -lpthread" The Hello program using threads. */ #include #include #include #define TOTALRUN 16 void moo(void * x); int main() { struct timespec maintime = {TOTALRUN, 0}; pthread_t theThread; if (pthread_create(&theThread, NULL, (void *)moo, NULL) != 0){ perror("pthread_create"); exit(1); } /* Wait a while then exit: all existing threads will die */ nanosleep(&maintime, NULL); return 0; } void moo(void * x) /* We assume that a thread sleeps one second in each iteration */ { struct timespec interval = {1, 0}; while (1){ printf ("Hello World!\n"); nanosleep(&interval, NULL); } }