From: H.G. Muller Date: Tue, 13 Sep 2011 17:55:44 +0000 (+0200) Subject: Fix write failures in concurrency X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=8e2df8ca84410f38449ed544cf115d2c470a52c5;p=xboard.git 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. --- 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);