// #include #include #include // #define N 4 // pthread_t arr[N]; int brr[N]; // void* showID( void* ptr ) { int id ; // id = *( (int*)ptr ) ; // printf( "*** %d ***\n" , id ) ; // pthread_exit( NULL ) ; } // int main() { int j , rc ; // pthread_t t_id ; // pthread_attr_t attr ; // // initialize // pthread_attr_init( &attr ) ; // pthread_attr_setdetachstate( &attr , PTHREAD_CREATE_JOINABLE ) ; // for( j = 0 ; j < N ; j++ ) brr[j] = j ; // // spawn ... need to define a function // for( j = 0 ; j < N ; j++ ) { rc = pthread_create( &t_id , &attr , showID , (void*)( brr + j ) ) ; // arr[j] = t_id ; // if( rc ) { printf( "ERROR; return code from pthread_create() is %d\n" , rc ) ; // exit(-1) ; } } // // join ... explicit // for( j = 0 ; j < N ; j++ ) { t_id = arr[j] ; // rc = pthread_join( t_id , NULL ) ; // if( rc ) { printf( "ERROR; return code from pthread_join() is %d\n" , rc ) ; // exit(-1) ; } } // // clean up // pthread_attr_destroy( &attr ) ; // pthread_exit( NULL ) ; // return 0; } // // gcc -lpthread demoPthreads.c //