void *t2_main(void *args) { init_local_storage(2); thread_work(); return NULL; }
void new_thread() { int c = int(work_threads.size()); if (c < max_num) { work_threads.resize(c + 1); auto w = std::thread([this](){ thread_work(); }); work_threads[c].swap(w); } }
int locktest() { int i; Workblk *array; struct scripttab *k; hrtime_t start; hrtime_t vstart; hrtime_t end; hrtime_t vend; struct timeval ttime; time_t secs; head.size = narrays; head.arrays = (Workblk *) calloc(narrays, sizeof(Workblk)); for(i = 0, array = head.arrays; i < narrays; i ++, array ++) { array->index = i; } printf( "%s: number of %s = %d, number of blocks = %d, repeat %d times %s\n", name, model, nthreads, narrays, repeat_count, (uniprocessor == 0 ? "" : "[single CPU]") ); #ifdef SOLARIS tid = (thread_t *) calloc(nthreads*repeat_count, sizeof(thread_t)); #endif #ifdef POSIX tid = (pthread_t *) calloc(nthreads*repeat_count, sizeof(pthread_t)); #endif for(count = 0; count < repeat_count; count ++) { (void) gettimeofday(&ttime, NULL); secs = (time_t)ttime.tv_sec; printf("Iteration %d, starting %s\n", count+1, prtime (&secs) ); if(job_index == -1) { for (i = 0; ; i++) { k = &scripttab[i]; if (k->test_name == NULL) { break; } printf("begin thread_work, %s\n", k->test_name); init_arrays(i); start = gethrtime(); vstart = gethrvtime(); if( strcmp(k->test_name, "nothreads") == 0 ){ /* the "nothreads" task is special-cased to run in the main thread */ do_work(NULL); } else if(nthreads == 1) { do_work(NULL); } else { thread_work(); } end = gethrtime(); vend = gethrvtime(); #if OS(Solaris) check_sigmask(2); #endif /* OS(Solaris) */ dump_arrays(end-start, vend-vstart, i); } } else { k = &scripttab[job_index]; if (k->test_name == NULL) { break; } printf("begin thread_work, %s\n", k->test_name); init_arrays(job_index); start = gethrtime(); vstart = gethrvtime(); if( strcmp(k->test_name, "nothreads") == 0 ){ /* first one is special-cased to run in 1 thread */ do_work(NULL); } else if(nthreads == 1) { do_work(NULL); } else { thread_work(); } end = gethrtime(); vend = gethrvtime(); #if OS(Solaris) check_sigmask(2); #endif /* OS(Solaris) */ dump_arrays(end-start, vend-vstart, job_index); } } /* we're done, return */ return(0); }
void thread_work_dist() { int tmp, tmp1; int rc, t, status; int excess, chunk; #if (NUM_THREADS>1) pthread_attr_t attr; pthread_t thread[NUM_THREADS-1]; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); #endif chunk = height2/NUM_THREADS; excess = (height2/16)%NUM_THREADS; for(t=0;t < NUM_THREADS;t++) { if (t==0) { thread_data_array[t].s_height = 0; thread_data_array[t].s_mbh = 0; thread_data_array[t].pp_smbh = 0; tmp = chunk; } else { thread_data_array[t].s_height = thread_data_array[t-1].e_height; thread_data_array[t].s_mbh = thread_data_array[t-1].e_mbh; thread_data_array[t].pp_smbh = thread_data_array[t-1].pp_embh; tmp = thread_data_array[t-1].e_height + chunk; } if (excess) { tmp = tmp + 16 - (tmp%16); excess--; } else { tmp = tmp - (tmp%16); } tmp1 = tmp/16; thread_data_array[t].e_height = tmp; thread_data_array[t].pp_embh = tmp1; thread_data_array[t].e_mbh = tmp1*mb_width; thread_data_array[t].id = t; thread_data_array[t].data_ptr = &data_args; #if (NUM_THREADS>1) /* create threads */ if (t<NUM_THREADS-1) { rc = pthread_create(&thread[t], &attr, thread_work, (void*) &thread_data_array[t]); if (rc) { printf("ERROR; return code from pthread_create() is %d\n", rc); exit(-1); } } #endif } #if (NUM_THREADS>1) /* Free attribute and wait for the other threads */ pthread_attr_destroy(&attr); #endif /* disabled rate control, detail can be found at putpic.c */ putpicthdr(); if (!mpeg1) putpictcodext(); alignbits(); /*align common bitstream buffer */ thread_work(&thread_data_array[NUM_THREADS-1]); #if (NUM_THREADS>1) for(t=0;t < NUM_THREADS-1;t++) { rc = pthread_join(thread[t], (void **)&status); if (rc) { printf("ERROR; return code from pthread_join() is %d\n", rc); exit(-1); } flushbits(t); } #endif flushbits(NUM_THREADS-1); }