previous | start | next

Barrier Problem (1)

Problem: Want to block threads until all n have been blocked, then release all (possibly repeat).

Not a solution:

    1     pthread_mutex_lock(&m);
    2     if (++count == number) {
    3     
    4       pthread_cond_broadcast(&cond_var);
    5     } else {
    6       while (!(count == number)) 
    7         {
    8           pthread_cond_wait(&cond_var, &m);
    9         }
   10     }
   11     pthread_mutex_unlock(&m);


previous | start | next