Are you sure ? Maybe you missed that (or maybe I'm wrong, we'll discover soon or later :p) but in
Code:
pthread_barrier_wait(&barrier);
for (i = 0; i < NB_ITER_THREAD; i++);
pthread_barrier_wait(&barrier);
There's 2 call to pthread_barrier_wait(). So, after the second call to pthread_barrier_wait() (by after I mean when the "first" thread will return from the call) , all the "work" will have been done. And by "work", to be sure we are talking about the same thing, i'm talking about the NB_ITER_TOTAL iterations of the loop (that's it, every thread will have done his NB_ITER_THREAD iterations).