From 8e2df8ca84410f38449ed544cf115d2c470a52c5 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Tue, 13 Sep 2011 19:55:44 +0200 Subject: [PATCH] Fix write failures in concurrency In WinBoard a flood of writes by differentprocesses to the same PGN can cause a "permission denied" error in fopen. This patch causes retries after a random (5-15 msec) wait, in such cases. --- backend.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/backend.c b/backend.c index 64b5f3d..c259cc5 100644 --- a/backend.c +++ b/backend.c @@ -11955,12 +11955,18 @@ SaveGameToFile(filename, append) { FILE *f; char buf[MSG_SIZ]; - int result; + int result, i, t,tot=0; if (strcmp(filename, "-") == 0) { return SaveGame(stdout, 0, NULL); } else { - f = fopen(filename, append ? "a" : "w"); + for(i=0; i<10; i++) { // upto 10 tries + f = fopen(filename, append ? "a" : "w"); + if(f && i) fprintf(f, "[Delay \"%d retries, %d msec\"]\n",i,tot); + if(f || errno != 13) break; + DoSleep(t = 5 + random()%11); // wait 5-15 msec + tot += t; + } if (f == NULL) { snprintf(buf, sizeof(buf), _("Can't open \"%s\""), filename); DisplayError(buf, errno); -- 1.7.0.4