Ole Tange <tange <at> gnu.org> writes:
> I will be positive towards a patch that makes --semaphore work better
> on Windows/Cygwin as long as it does not break existing functionality
> on other platforms - especially the free platforms.
--- origsrc/parallel-20140422/src/parallel 2014-04-22 10:17:19.000000000
+0200
+++ src/parallel-20140422/src/parallel 2014-05-19 13:03:10.141273300 +0200
@@ -6905,8 +6905,12 @@ sub nlinks {
sub lock {
my $self = shift;
my $sleep = 100; # 100 ms
- open $self->{'lockfh'}, ">", $self->{'lockfile'}
- or ::die_bug("Can't open semaphore file $self->{'lockfile'}: $!");
+ my $tries = 5;
+ until (open $self->{'lockfh'}, ">", $self->{'lockfile'}) {
+ ::usleep(rand(5000));
+ --$tries
+ or ::die_bug("Can't open semaphore file $self->{'lockfile'}: $!");
+ }
chmod 0666, $self->{'lockfile'}; # assuming you want it a+rw
$Global::use{"Fcntl"} ||= eval "use Fcntl qw(:DEFAULT :flock); 1;";
while(not flock $self->{'lockfh'}, LOCK_EX()|LOCK_NB()) {
--- origsrc/parallel-20140422/src/sem 2014-04-22 10:17:19.000000000 +0200
+++ src/parallel-20140422/src/sem 2014-05-19 13:02:40.241283600 +0200
@@ -6905,8 +6905,12 @@ sub nlinks {
sub lock {
my $self = shift;
my $sleep = 100; # 100 ms
- open $self->{'lockfh'}, ">", $self->{'lockfile'}
- or ::die_bug("Can't open semaphore file $self->{'lockfile'}: $!");
+ my $tries = 5;
+ until (open $self->{'lockfh'}, ">", $self->{'lockfile'}) {
+ ::usleep(rand(5000));
+ --$tries
+ or ::die_bug("Can't open semaphore file $self->{'lockfile'}: $!");
+ }
chmod 0666, $self->{'lockfile'}; # assuming you want it a+rw
$Global::use{"Fcntl"} ||= eval "use Fcntl qw(:DEFAULT :flock); 1;";
while(not flock $self->{'lockfh'}, LOCK_EX()|LOCK_NB()) {
Regards,
Achim.