[Zlib-devel] zlib 1.2.4.4 -- a 1.2.5 release candidate

Török Edwin edwintorok at gmail.com
Sun Apr 18 13:15:16 EDT 2010


On 2010-04-18 19:20, Mark Adler wrote:
> On Apr 18, 2010, at 3:38 AM, Török Edwin wrote:
>> How about this patch (silences the mkdir failure, since there is an inherent race condition between the if and mkdir):
> ...
>> -       - at if [ ! -d objs ]; then mkdir objs; fi
> 
> A race condition?  How can that be?  Of what use is an if statement if the "then" can execute before the "if" is finished?

No I don't mean it like that.
I mean that between the test in the "if", and the action in the "then"
another command can be executed by parallel make, the "if [! -d objs;]
then mkdir objs" is not atomic.
Hence by the time you reach mkdir the directory may exist.

This scenario is entirely plausible on a dual-core machine (and even
single-core if you consider a task-switch):
 objs doesn't exist
 make thread 1 - core 1:
   if [ ! -d objs ];
   objs doesn't exist, proceeding with then
 make thread 2 - core 2:
   if [ ! -d objs];
 make thread 1 - core 1:
   creates objs dir
 make thread 2 - core 2:
   tries to create objs, but it exists already

Indeed 1.2.4.3 doesn't show this error, and 1.2.4.4 shows this error
with make -j8 on a quad-core machine each time.
Maybe a file takes longer/shorter to compile and triggers this race
condition?

Best regards,
--Edwin




More information about the Zlib-devel mailing list