IPC::SRLock - Set / reset locking semantics to single thread processes
This documents version v0.31.$Rev: 2 $ of IPC::SRLock
use IPC::SRLock;
my $config = { tempdir => 'path_to_tmp_directory', type => 'fcntl' };
my $lock_obj = IPC::SRLock->new( $config );
$lock_obj->set( k => 'some_resource_identfier' );
# This critical region of code is guaranteed to be single threaded
$lock_obj->reset( k => 'some_resource_identfier' );
Provides set/reset locking methods which will force a critical region of code to run single threaded
Implements a factory pattern, three implementations are provided. The
LCD option IPC::SRLock::Fcntl which works on non Unixen,
IPC::SRLock::Sysv which uses System V IPC, and
IPC::SRLock::Memcached which uses libmemcache
to implement a
distributed lock manager
Defines the following attributes;
-
type
Determines which factory subclass is loaded. Defaults to
fcntl
, can be;fcntl
,memcached
, orsysv
Extracts the type
attribute from those passed to the factory subclass
Called after an instance is created this subroutine triggers the lazy evaluation of the concrete subclass
my $data = $lock_obj->get_table;
Returns a hash ref that contains the current lock table contents. The keys/values in the hash are suitable for passing to HTML::FormWidgets
my $array_ref = $lock_obj->list;
Returns an array of hash refs that represent the current lock table
$lock_obj->reset( k => 'some_resource_key' );
Resets the lock referenced by the k
attribute.
$lock_obj->set( k => 'some_resource_key' );
Sets the specified lock. Attributes are:
-
k
Unique key to identify the lock. Mandatory no default
-
p
Explicitly set the process id associated with the lock. Defaults to the current process id
-
t
Set the time to live for this lock. Defaults to five minutes. Setting it to zero makes the lock last indefinitely
Setting debug
to true will cause the set
methods to log
the lock record at the debug level
The sysv
subclass type will not work on MSWin32
and cygwin
platforms
Testing of the memcached
subclass type is skipped on all platforms as it
requires memcached
to be listening on the localhost's default
memcached port localhost:11211
There are no known bugs in this module. Please report problems to the address below. Patches are welcome
Peter Flanigan, <pjfl@cpan.org>
Copyright (c) 2021 Peter Flanigan. All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic
This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE