GT::Lock - a small autonomous locking module.
use GT::Lock qw/lock unlock LOCK_TRY LOCK_FORCE/;
# attempt to lock foobar for 10 seconds
if ( lock 'foobar', 10, LOCK_TRY ) {
# do some code that needs to be locked
unlock 'foobar';
}
else {
# oops out lock failed
die "Lock failed: $GT::Lock::error\n";
}
GT::Lock is a very simple module to impliment autonomous named locking. Locking can be used for many things but is most commonly used to lock files for IO to them.
Nothing is exported by default. You may request the lock, unlock routines be exported. You can also get the two constants for lock types exported: LOCK_TRY and LOCK_FORCE.
lock NAME [, TIMOUT, TYPE ]
This method is used to create a lock. It't arguments are the name you wish to give the lock, the timeout in second for the lock to happen, and the type of lock. The types are LOCK_FORCE and LOCK_TRY. If LOCK_FORCE is given a lock always succeeds, e.g. if the lock times out the lock is removed and your lock succeeds. Try attempts to get the lock and returns false if the lock can not be had in the specified TIMEOUT. If TIMEOUT is zero this method will attempt to lock forever. TIMEOUT defaults to 10 seconds.
unlock NAME
This method is used to unlock a name. It's argument is the name of the lock to unlock. Returns true on success and false on errors and sets the error in $GT::Lock::error
the GT::Lock manpage depends on the GT::TempFile manpage, bases, and constants.
Copyright (c) 2000 Gossamer Threads Inc. All Rights Reserved. http://www.gossamer-threads.com/
Revision: $Id: Lock.pm,v 1.3 2002/04/07 03:35:35 jagerman Exp $