Skip to content

Commit

Permalink
lab barrier finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Nowherechan committed Mar 29, 2023
1 parent a460334 commit 3f0756e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions notxv6/barrier.c
Expand Up @@ -31,6 +31,17 @@ barrier()
// then increment bstate.round.
//

pthread_mutex_lock(&bstate.barrier_mutex);
bstate.nthread += 1;
if (nthread == bstate.nthread) {
bstate.nthread = 0;
bstate.round += 1;
pthread_mutex_unlock(&bstate.barrier_mutex);
pthread_cond_broadcast(&bstate.barrier_cond);
return;
}
pthread_cond_wait(&bstate.barrier_cond, &bstate.barrier_mutex);
pthread_mutex_unlock(&bstate.barrier_mutex);
}

static void *
Expand Down

0 comments on commit 3f0756e

Please sign in to comment.