void *sleepTreatment(void *unused) { int sleep = randSleep((1 << waitNb) * waitDefaultTime * 1000); //printf("waiting time : %d\n", sleep); usleep(sleep * 1000); waitNb++; offlineInit(); return NULL ; }
unsigned __stdcall processDataThread( void *arg ) { CRYPT_CONTEXT cryptContext; BYTE buffer[ 1024 ]; int threadNo = ( int ) arg; int status; randSleep(); memset( buffer, '*', 1024 ); status = cryptCreateContext( &cryptContext, CRYPT_UNUSED, CRYPT_ALGO_3DES ); if( cryptStatusOK( status ) ) { randSleep(); status = cryptSetAttributeString( cryptContext, CRYPT_CTXINFO_KEY, "123456781234567812345678", 24 ); } if( cryptStatusOK( status ) ) { randSleep(); status = cryptEncrypt( cryptContext, buffer, 1024 ); } if( cryptStatusOK( status ) ) { randSleep(); status = cryptEncrypt( cryptContext, buffer, 0 ); } if( cryptStatusOK( status ) ) { randSleep(); status = cryptDestroyContext( cryptContext ); } if( cryptStatusError( status ) ) printf( "\nEncryption failed with status %d.\n", status ); else printf( "%d ", threadNo ); _endthreadex( 0 ); return( 0 ); }
/* Consumer Thread */ void *T2(void *t) { printf("Consumer Started\n"); struct LList *ll = (struct LList*) t; int queue_value; while (!done) { usleep(randSleep()); pthread_mutex_lock(&count_mutex); if (size != 0) { /* Remove from Queue */ queue_value = getEntry(ll); size--; printf("Consumer removed %d, computed %d! = %d, queue size = %d\n", queue_value, queue_value, getFactorial(queue_value), size); /* Pthread Mutex Locks */ } else { pthread_cond_wait(&count_cond, &count_mutex); } pthread_mutex_unlock(&count_mutex); } pthread_exit(NULL); }
/* Producer Thread */ void * T1(void *t) { printf("Producer Started\n"); struct LList *ll = (struct LList*) t; int value; while (!done) { usleep(randSleep()); pthread_mutex_lock(&count_mutex); if (size == 10) { printf("Queue is full\n"); } else { /* Add to Queue */ value = randGen(); AddEntry(ll, value); size++; printf("Producer added %d to queue, size = %d\n", value, size); /* Wake up Threads and Mutex Locks */ pthread_cond_broadcast(&count_cond); } pthread_mutex_unlock(&count_mutex); } pthread_exit(NULL); }