Dir-Flock
view release on metacpan or search on metacpan
}
print STDERR "Acquired lock\n";
do_synchronized_things();
$z = Dir::Flock::flock $dir, LOCK_UN;
# scoping semantics
{
my $mutex = Dir::Flock::lockobj( $somedir );
do_synchronized_things();
} # unlocked as $mutex goes out of scope
# code block semantics
Dir::Flock::sync { do_synchronized_things() } "/some/directory";
INSTALLATION
To install this module, follow the usual recipe:
lib/Dir/Flock.pm view on Meta::CPAN
=head2 lock
=head2 lock_ex
=head2 $success = Dir::Flock::lock( $directory [, $timeout ] )
=head2 $success = Dir::Flock::lock_ex( $directory [, $timeout ] )
Attempts to obtain an I<exclusive> lock on the given directory. While
the directory is locked, the C<lock> or C<lock_sh> call on the
same directory from
other processes or threads will block until the directory is unlocked
(see L<"unlock">). Returns true if the lock was successfully acquired.
Note that the first argument is a path name, not a directory I<handle>.
If an optional C<$timeout> argument is provided, the function will
try for at least C<$timeout> seconds to acquire the lock, and return
a false value if it is not successful in that time. Use a timeout of
zero to make a "non-blocking" request for an exclusive lock.
=head2 lock_sh
( run in 1.189 second using v1.01-cache-2.11-cpan-49f99fa48dc )