/***************************************************************************** * SOURCE: This is a translation of a Pthread program from the Lawrence Livermore * Computing Center POSIX Threads Programming Exercise at: * https://computing.llnl.gov/tutorials/pthreads/exercise.html * FILE: detached.cvl * DESCRIPTION: * This example demonstrates how to explicitly create a thread in a * detached state. This might be done to conserve some system resources * if the thread never needs to join later. Compare with the join.cvl program * where the threads are created joinable. * Command line execution: * civl verify -inputNUM_THREADS=4 detached.cvl ******************************************************************************/ #include "pthread.cvh" #include #include #include $input int NUM_THREADS; void *BusyWork(void *t) { long i, tid; double result=0.0; tid = (long)t; printf("Thread %ld starting...\n",tid); for (i=0; i<1000000; i++) { result = result + sin(i) * tan(i); } printf("Thread %ld done. Result = %e\n",tid, result); } int main(int argc, char *argv[]) { pthread_t thread[NUM_THREADS]; pthread_attr_t attr; int rc; long t; /* Initialize and set thread detached attribute */ pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); for(t=0;t