diff options
Diffstat (limited to 'notxv6/barrier.c')
-rw-r--r-- | notxv6/barrier.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/notxv6/barrier.c b/notxv6/barrier.c index 12793e8..b7737a6 100644 --- a/notxv6/barrier.c +++ b/notxv6/barrier.c @@ -25,12 +25,20 @@ barrier_init(void) static void barrier() { - // YOUR CODE HERE - // // Block until all threads have called barrier() and // then increment bstate.round. - // - + pthread_mutex_lock(&bstate.barrier_mutex); + bstate.nthread++; + if(bstate.nthread != nthread) { + pthread_cond_wait(&bstate.barrier_cond, &bstate.barrier_mutex); + } else { + pthread_cond_broadcast(&bstate.barrier_cond); + // All threads have reached barrier. + // reset and increase round + bstate.nthread = 0; + bstate.round++; + } + pthread_mutex_unlock(&bstate.barrier_mutex); } static void * |