Skip to content

Commit

Permalink
Unlink output files before opening them; seems to resolve weird error…
Browse files Browse the repository at this point in the history
… when two overlap jobs write to same output.
  • Loading branch information
brianwalenz committed Jul 24, 2019
1 parent 6521c02 commit be81b1a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/utility/files.C
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,18 @@ AS_UTL_openOutputFile(char const *prefix,
fprintf(stderr, "AS_UTL_openOutputFile()-- Creating '%s'.\n", filename);
#endif

// Unlink the file before opening for writes. This prevents race
// conditions when two processes open the same file: the first process
// will create a new file, but the second process will simply reset the
// file to the start. Both processes seem to keep their own file pointer,
// and eof seems to be (incorrectly) the larger of the two. In effect,
// the second process is simply overwriting the first process (unless the
// second process writes data first, then the first process overwrites).
//
// Very confusing.
//
AS_UTL_unlink(filename);

errno = 0;

FILE *F = fopen(filename, "w");
Expand Down

0 comments on commit be81b1a

Please sign in to comment.