- if(assert != MPI_MODE_NOPRECEDE){
- xbt_barrier_wait(win->bar);
-
- xbt_dynar_t reqs = win->requests;
- int size = xbt_dynar_length(reqs);
- unsigned int cpt=0;
- MPI_Request req;
+ if (assert != MPI_MODE_NOPRECEDE) {
+ // This is not the first fence => finalize what came before
+ MSG_barrier_wait(win->bar);
+ xbt_mutex_acquire(win->mut);
+ // This (simulated) mutex ensures that no process pushes to the vector of requests during the waitall.
+ // Without this, the vector could get redimensionned when another process pushes.
+ // This would result in the array used by smpi_mpi_waitall() to be invalidated.
+ // Another solution would be to copy the data and cleanup the vector *before* smpi_mpi_waitall
+ std::vector<MPI_Request> *reqs = win->requests;
+ int size = static_cast<int>(reqs->size());