Subject: | [Patch] Support for threads |
Hi Steffen,
I have been trying to use File::SharedNFSLock for a script that uses
threads. Unfortunately, I found that the module did not work as
expected. But after some debugging, I found out that it simply different
perl threads as the same entity.
I created a patch for this (attached. the important lines are 252-253,
the rest is trivial stuff). After applying the patch, the module seems
to work as expected on my Linux, non-NFS box.
On an unrelated note, it seems like hard links are not supported on
Windows (https://rt.cpan.org/Public/Bug/Display.html?id=33932). That
means that the module is ineffective on Windows, correct? That would be
good to document it if that's the case. Is there any solution to make
the module truly cross-platform?
Thanks for the good work,
Florent
Subject: | thread_patch.diff |
132c132,133
< ."Time out for stale locks: $self->{timeout_stale}";
---
> ."Time out for stale locks: $self->{timeout_stale}\n"
> ."Poll interval : $self->{poll_interval}\n";
147c148
< warn "Getting lock on " . $self->{file} if DEBUG;
---
> warn "Getting lock on ".$self->{file}."\n" if DEBUG;
150c151
< warn "It's not locked already... " . $self->{file} if DEBUG;
---
> warn "It is locked already... ".$self->{file}."\n" if DEBUG;
152a154
> warn "Before time is $before_time\n" if DEBUG;
154,155c156
< my $got_lock = $self->_write_lock_file();
< if ($got_lock) {
---
> if ($self->_write_lock_file()) {
157,158c158
< }
< else {
---
> } else {
160,165c160,163
< my $stale = $self->_is_stale_lock;
< if ($stale) {
< unlink($self->_lock_file);
< unlink($self->_unique_lock_file);
< }
< else {
---
> if ($self->_is_stale_lock) {
> unlink $self->_lock_file;
> unlink $self->_unique_lock_file;
> } else {
167a166
> warn "Time now is $now\n" if DEBUG;
205c204
< warn "locked: LOCKED with " . $self->_unique_lock_file if DEBUG;
---
> warn "locked: LOCKED with ".$self->_unique_lock_file."\n" if DEBUG;
209c208
< warn "locked: NOT LOCKED with " . $self->_unique_lock_file if DEBUG;
---
> warn "locked: NOT LOCKED with ".$self->_unique_lock_file."\n" if DEBUG;
222c221
< warn "_unlink_lock_file: locked, removing main lock file" if DEBUG;
---
> warn "_unlink_lock_file: locked, removing main lock file\n" if DEBUG;
225c224
< warn "_unlink_lock_file: removing unique lock file" if DEBUG;
---
> warn "_unlink_lock_file: removing unique lock file\n" if DEBUG;
243c242
< warn "_write_lock_file: HAVE LOCK!" if DEBUG;
---
> warn "_write_lock_file: HAVE LOCK!\n" if DEBUG;
253c252,253
< my $unique_lock_file = "$lock_file." . $self->{hostname} . ".$$." . $self->{token};
---
> my $thread_id = exists $INC{'threads.pm'} ? threads->tid : '';
> my $unique_lock_file = "$lock_file." . $self->{hostname} . ".$$.$thread_id." . $self->{token};