https://github.com/Kitware/CMake
Raw File
Tip revision: f872033d7531ed1d7d7345ff7873442ec8dbcee1 authored by Brad King on 14 May 2019, 15:33:06 UTC
CMake 3.14.4
Tip revision: f872033
lockFile.c
#include <stdio.h>

/*if run serially, works fine.
  If run in parallel, someone will attempt to delete
  a locked file, which will fail */
int main(void)
{
  FILE* file;
  int i;
  const char* fname = "lockedFile.txt";
  file = fopen(fname, "w");

  for (i = 0; i < 10000; i++) {
    fprintf(file, "%s", "x");
    fflush(file);
  }
  fclose(file);
  return remove(fname);
}
back to top