Paranoid::IO::Lockfile(3) Paranoid Lockfile support

VERSION

$Id: lib/Paranoid/IO/Lockfile.pm, 2.01 2016/06/23 00:34:49 acorliss Exp $

SYNOPSIS


use Paranoid::IO::Lockfile;
use Fcntl qw(:flock); # only needed if you use plock in lieu
# of the other functions
$rv = plock($lockfile);
$rv = plock($lockfile, LOCK_SH | LOCK_NB);
$rv = plock($lockfile, LOCK_SH | LOCK_NB, $mode);
$rv = pexclock($lockfile);
$rv = pshlock($lockfile);
$rv = punlock($lockfile);

DESCRIPTION

This module provides convenience functions for using a lockfile to coordinate multi-process activities. While basically just a thin wrapper for Paranoid::IO functions it removes the small tedium of having to perform the multiple opens required to ensure all processes are working off the same files while avoiding race conditions.

SUBROUTINES/METHODS

plock

  $rv = plock($filename);
  $rv = plock($filename, LOCK_EX);
  $rv = plock($filename, LOCK_EX, 0666);

Creates or opens the requested file while applying the lock condition. The lock type defaults to LOCK_EX if omitted, while the file permissions default to 0660. As always, umask applies.

There is one scenario in which one would want to use plock in lieu of pexclock, etc: if you wish to perform non-blocking lock attempts. All convenience functions are blocking.

pexclock

  $rv = pexclock($filename);
  $rv = pexclock($filename, $mode);

A wrapper for plock($filename, LOCK_EX).

pshlock

  $rv = pshlock($filename);
  $rv = pshlock($filename, $mode);

A wrapper for plock($filename, LOCK_SH).

punlock

  $rv = punlock($filename);
  $rv = punlock($filename, $mode);

A wrapper for plock($filename, LOCK_UN). This does not close the open file handle to the lock file. For that you need to call Paranoid::IO's pclose function.

DEPENDENCIES

  • Fcntl
  • Paranoid
  • Paranoid::Debug
  • Paranoid::IO

BUGS AND LIMITATIONS

AUTHOR

Arthur Corliss ([email protected])

LICENSE AND COPYRIGHT

This software is licensed under the same terms as Perl, itself. Please see http://dev.perl.org/licenses/ for more information.

(c) 2005 - 2015, Arthur Corliss ([email protected])