/***************************************************************************** * FILE: join1.c * DESCRIPTION: * This example demonstrates how to "wait" for thread completions by using * the Pthread join routine. Since not all current implementations of * Pthreads create threads in a joinable state, the threads in this * example are explicitly created in an undetached state so that they can * be joined later. * * SOURCE: 8/98 Blaise Barney * LAST REVISED: 9/20/98 Blaise Barney ******************************************************************************/ #include #include #define NUM_THREADS 3 void *BusyWork(void *null) { int i; double result=0.0; for (i=0; i<1000000; i++) { result = result + (double)random(); } printf("result = %d\n",result); pthread_exit(NULL); } void main() { pthread_t thread[NUM_THREADS]; pthread_attr_t attr; int rc, t; /* Initialize and set thread detached attribute */ pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_UNDETACHED); for(t=0;t