unsigned count = __sync_add_and_fetch(&parmap->thread_counter, 1);
if (count == parmap->num_workers) {
/* all workers have finished, wake the controller */
unsigned count = __sync_add_and_fetch(&parmap->thread_counter, 1);
if (count == parmap->num_workers) {
/* all workers have finished, wake the controller */
parmap->thread_counter = 1;
__sync_add_and_fetch(&parmap->work, 1);
/* wake all workers */
parmap->thread_counter = 1;
__sync_add_and_fetch(&parmap->work, 1);
/* wake all workers */