Bug 4396 – mkdir race prevents concurrent compiling with DMD using make -j

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-06-27T07:10:00Z
Last change time
2015-06-09T05:10:43Z
Keywords
patch
Assigned to
nobody
Creator
leandro.lucarella

Comments

Comment #0 by leandro.lucarella — 2010-06-27T07:10:43Z
Since DMD creates directories as needed, when using make -j to compile some modules concurrently, if 2 modules lives in the same directory, that directory doesn't exist and both are compiled at the same time, there are times where this set of steps are performed: 1) dmd m1.d checks if dstdir exist (it doesn't) 2) dmd m2.d checks if dstdir exist (it doesn't) 3) dmd m1.d creates dstdir successfully 4) dmd m2.d tries to create dstdir but it fails because dmd m1.d already created it. Here is a simple patch. Created against D1 svn but I guess it will apply to D2 cleanly also. --- diff --git a/src/root/root.c b/src/root/root.c index 3d491a4..9df951c 100644 --- a/src/root/root.c +++ b/src/root/root.c @@ -957,7 +957,10 @@ void FileName::ensurePathExists(const char *path) #if POSIX if (mkdir(path, 0777)) #endif - error("cannot create directory %s", path); + { + if (errno != EEXIST) + error("cannot create directory %s", path); + } } } } --- I'm not sure how the mkdir() API for windows behaves regarding errno, I couldn't find any reference of mkdir() for windows. Adding a strerror() to the error message could be useful too.
Comment #1 by bugzilla — 2010-06-29T09:33:25Z
Comment #2 by leandro.lucarella — 2010-06-29T10:32:22Z
Thanks!
Comment #3 by gide — 2010-07-01T00:16:31Z
Commit 569 reverted the change.
Comment #4 by bugzilla — 2010-07-01T10:57:31Z