IPC::SRLock - Set / reset locking semantics to single thread processes
This documents version v0.31.$Rev: 1 $ 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
libmemcache
Defines the following attributes;
type
Determines which factory subclass is loaded. Defaults to fcntl, can be; fcntl, memcached, or sysv
fcntl
memcached
sysv
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.
k
$lock_obj->set( k => 'some_resource_key' );
Sets the specified lock. Attributes are:
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
debug
set
The sysv subclass type will not work on MSWin32 and cygwin platforms
MSWin32
cygwin
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
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>
<pjfl@cpan.org>
Copyright (c) 2017 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
To install IPC::SRLock, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IPC::SRLock
CPAN shell
perl -MCPAN -e shell install IPC::SRLock
For more information on module installation, please visit the detailed CPAN module installation guide.