// CS 450; Thread example 1: pthread_create, pthread_join // version 2014-01-25 3:43 PM // #include #include void *task(void *arg); // prototype int main(void) { pthread_t thd; // thread int retcode; // 0 if thread creation succeeded // Create thread and have it run task // retcode = pthread_create(&thd, NULL, task, NULL); printf("Thread creation returned code = %d\n", retcode); // Wait for thread to finish // if (retcode == 0) { pthread_join(thd, NULL); // Wait for thread to complete } } // Task run by thread; this one just prints a message. // void *task(void *arg) { printf("Thread called\n"); return NULL; } /* Output: Thread creation returned code = 0 Thread called */