I have downloaded the source code for the MCS lock from the excellent book "Using Advanced MPI" from
I have made a very simple piece of test code for testing the MCS lock but it works at random and often never escapes the busy loops in the acquire and release functions (see attached source code). The code appears semantically correct to my eyes.
#include <stdio.h>
#include <mpi.h>
#include "mcs-lock.h"
int main(int argc, char *argv[])
{
MPI_Win win;
MPI_Init( &argc, &argv );
MCSLockInit(MPI_COMM_WORLD, &win);
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
printf("rank: %d, size: %d\n", rank, size);
MCSLockAcquire(win);
printf("rank %d aquired lock\n", rank); fflush(stdout);
MCSLockRelease(win);
MPI_Win_free(&win);
MPI_Finalize();
return 0;
}