[PATCH][libgomp] Second attempt: Thread pool for nested threads

Jakob Blomer jakob.blomer@gmx.net
Thu Aug 21 21:03:00 GMT 2008


> -  if (!__sync_bool_compare_and_swap (sem, 0, 1))
> -    gomp_sem_post_slow (sem);
> +  //if (!__sync_bool_compare_and_swap (sem, 0, 1))
> +    gomp_sem_post_slow (sem, 1);
> 
> Why are you commenting out the swap?  It avoids the function
> call and the loop if there are no waiters.

If there are $n$ threads waiting on a semaphore and they are waken up by 
two consecutive gomp_sem_post calls, the second call doesn't really wake 
up anything.

The problem is that the semaphore has value 0 after the first 
gomp_sem_post call. The second call uses the "fast mode" 
(compare_and_swap(0, 1)) without calling futex_wake.

This is just a workaround. Jakub confirmed that the gomp_sem_t is not a 
general purpose semaphore.

Cheers,
Jakob



More information about the Gcc-patches mailing list