The Perl Toolchain Summit 2025 Needs You: You can help 🙏 Learn more

NAME

IPC::Lock - simple and safe local/network locking

SYNOPSIS

IPC::Lock is a base module and depends on other objects to implement it.
Current modules include IPC::Lock::Memcached.
Please refer to a child module for their respective usage.
Generally, you instantiate a $lock object via new. The new will contain
connection parameters.
Then call
$lock->lock($key)
where $key is a unique identifier. The default value set for the lock comes
from $self->atomic_value, which by default is
return "$self->{hostname}:$$:" . scalar gettimeofday;
The value can potentially be used for debugging.
When $lock leaves scope,
$lock->unlock
gets called. When called via destroy, unlock will destroy the last
$key that was locked. To avoid relying on this magic, call
$lock->unlock explicitly.

PARAMETERS

The following parameters can be set in the instantiation:
ttl - number of seconds the lock should last, default is 60
patience - number of seconds to wait for a lock, default is 2
increment - number of seconds to wait between atomic attempts, default is 0.05
So, to instantiate with a ttl of a day, patience of a minute and increment of a second
my $lock = IPC::Lock::Child->new({
ttl => 86400,
patience => 60,
increment => 1,
});

DESCRIPTION

Simple way to lock across multiple boxes. Child modules need to implement two methods
atomic - a way to lock atomically
unatomic - a way to undo your atomic function

THANKS

Thanks to Perrin Harkins for suggesting the IPC::Lock namespace. Thanks to File::NFSLock for graceful_sig.

AUTHOR

Earl Cahill, <cpan@spack.net>

COPYRIGHT AND LICENSE

Copyright (C) 2005 by Earl Cahill

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.