--- joko/Uni/BSArch/04/bmp_fractal.c 2006/07/02 12:08:10 1.15 +++ joko/Uni/BSArch/04/bmp_fractal.c 2006/07/02 12:21:01 1.16 @@ -5,7 +5,7 @@ * Uebung 4.4 */ -// $Id: bmp_fractal.c,v 1.15 2006/07/02 12:08:10 joko Exp $ +// $Id: bmp_fractal.c,v 1.16 2006/07/02 12:21:01 joko Exp $ #include #include @@ -156,7 +156,6 @@ } -//BOOL scan_argv(int argc, char *argv[], char opt_name[], char *opt_value[]) { BOOL scan_argv(int argc, char *argv[], char opt_name[], char *opt_value) { int i; char * opt_current_name; @@ -187,10 +186,11 @@ unsigned char *pDataBitmap; // workers - int workers = 5; + int workers; int worker_index, worker_rows, worker_startrow; HANDLE *worker_handles; PWORKERARGS worker_args; + int worker_count; // threads or processes? BOOL use_processes = FALSE; @@ -427,11 +427,15 @@ } - // wait for all threads if (VERBOSE) fprintf(stdout, "waiting for workers to finish...\n"); - if (WaitForMultipleObjects(workers, worker_handles, TRUE, INFINITE) == WAIT_FAILED) - printErrorAndExit("Error at WaitForMultipleObjects", GetLastError()); + + // wait for all workers + for (worker_index = 0; worker_index < workers; worker_index += MAXIMUM_WAIT_OBJECTS) { + worker_count = ((workers - worker_index) > MAXIMUM_WAIT_OBJECTS) ? MAXIMUM_WAIT_OBJECTS : (workers - worker_index); + if (WaitForMultipleObjects(worker_count, &worker_handles[worker_index], TRUE, INFINITE) == WAIT_FAILED) + printErrorAndExit("Error at WaitForMultipleObjects", GetLastError()); + } // debugging: just run single thread //if (WaitForSingleObject(worker_handles[0], INFINITE) == WAIT_FAILED)