地址:Barriers
这次作业的目的是实现线程间的同步。具体实现参考别人如下:
static void
barrier()
{
//bstate.round++;
pthread_mutex_lock(&bstate.barrier_mutex );
bstate.nthread++;
if (bstate.nthread == nthread) {
// 最后一个进程进入 执行 round++, 再唤醒其他进程。
bstate.round++;
bstate.nthread = 0;
// 唤醒其他进程
pthread_cond_broadcast(&bstate.barrier_cond);
}
else {
pthread_cond_wait( &bstate.barrier_cond, &bstate.barrier_mutex);
}
pthread_mutex_unlock(&bstate.barrier_mutex );
}