- if (mutex == NULL) { // first arriving on the barrier
- mutex = simcall_mutex_init();
- cond = simcall_cond_init();
- processes_arrived_sofar = 0;
+ if (barrier == NULL) { // first arriving on the barrier
+ msg_bar_t newbar = MSG_barrier_init(communicator_size); // This is a simcall, unscheduling the current process
+ if (barrier == NULL) // Still null, commit our new value
+ barrier = newbar;
+ else // some other process commited a new barrier before me, so dismiss mine
+ MSG_barrier_destroy(newbar);