void main_loop_io_worker_init(void) { main_loop_io_workers.max_threads = MIN(MAX(MAIN_LOOP_MIN_WORKER_THREADS, get_processor_count()), MAIN_LOOP_MAX_WORKER_THREADS); main_loop_io_workers.thread_start = (void (*)(void *)) main_loop_worker_thread_start; main_loop_io_workers.thread_stop = (void (*)(void *)) main_loop_worker_thread_stop; iv_work_pool_create(&main_loop_io_workers); log_queue_set_max_threads(MIN(main_loop_io_workers.max_threads, MAIN_LOOP_MAX_WORKER_THREADS)); }
int main(void) { pool.preload_threads(8); // reserve 8 threads for work printf("This PC has %d processors\n", get_processor_count()); for (int numThreads = 1; numThreads <= MAX_THREADS_TO_RUN; numThreads *= 2) { printf("Using %d processors for internal calculations.\n", numThreads); DoWork dowork(numThreads); time_t xt = time(NULL); pool.run(&dowork, numThreads); xt = time(NULL) - xt; double sum = 0; for (int i = 0; i < numThreads; i++) { printf("Processor %d gave %.5lf as result\n", i, dowork.data[i]); sum += dowork.data[i]; } printf("pi = %.9lf\n", sqrt(sum * 6.0)); printf("Result produced in %u sec\n", (unsigned)xt); } return 0; }