12 int pthread_barrier_init(pthread_barrier_t *barrier,
const pthread_barrierattr_t *attr,
unsigned int count)
19 if(pthread_mutex_init(&barrier->mutex, 0) < 0)
23 if(pthread_cond_init(&barrier->cond, 0) < 0)
25 pthread_mutex_destroy(&barrier->mutex);
28 barrier->tripCount = count;
34 int pthread_barrier_destroy(pthread_barrier_t *barrier)
36 pthread_cond_destroy(&barrier->cond);
37 pthread_mutex_destroy(&barrier->mutex);
41 int pthread_barrier_wait(pthread_barrier_t *barrier)
43 pthread_mutex_lock(&barrier->mutex);
45 if(barrier->count >= barrier->tripCount)
48 pthread_cond_broadcast(&barrier->cond);
49 pthread_mutex_unlock(&barrier->mutex);
54 pthread_cond_wait(&barrier->cond, &(barrier->mutex));
55 pthread_mutex_unlock(&barrier->mutex);