yes, there is a race condition, which we discussed briefly on IRC. i stayed away from fcntl/flock for portability reasons, but i honestly didn't spend too much time researching it.

that said, i'm all for avoiding race conditions, so i'd be curious to see some platform tests with the fnctl patch, especially on windows.

-jeff

On Wed, 26 Sep 2007, chromatic wrote:

On Wednesday 26 September 2007 14:26:20 [EMAIL PROTECTED] wrote:

Author: coke
Date: Wed Sep 26 14:26:19 2007
New Revision: 21613

Modified:
   trunk/lib/Parrot/Configure/Messages.pm
   trunk/tools/build/c2str.pl

Log:
[build]

Update c2str.pl so that multiple copies running simultaneously no longer
step on each other's toes drunkenly with a jackhammer.

With this fix (Courtesy of jhorwitz++), 'make -j 2' now works, tested
on a variety of platforms.

It even works for make -j 9 for me (two cores, but I like to keep them busy).
However...

Modified: trunk/tools/build/c2str.pl
===========================================================================
=== --- trunk/tools/build/c2str.pl      (original)
+++ trunk/tools/build/c2str.pl  Wed Sep 26 14:26:19 2007
@@ -19,6 +19,21 @@

 my $outfile          = 'all_cstring.str';
 my $string_private_h = 'src/string_private_cstring.h';
+my $lockfile         = "$outfile.lck";
+my $max_lock_wait    = 120;
+
+my $start_time = time;
+while ( -e $lockfile ) {
+    sleep 1;
+    if ( time - $start_time > $max_lock_wait ) {
+        die "Lock still held after $max_lock_wait seconds -- something is
wrong!"; +    }
+}

... isn't there a race condition right here?

+open my $lock, '>', $lockfile or die "Can't write '$lockfile': $!";
+print $lock "$$\n";
+close $lock;
+
+$SIG{'__DIE__'} = sub { unlink $lockfile };

For what it's worth, I think this patch is safer.  I did have some trouble
with -j 3 and higher, but it's working for me on 32-bit x86 Linux now up
to -j 9.

-- c


Reply via email to