module Nfs:sig
..end
There are a few caveats compared to local file locks:
val create : ?message:string -> string -> bool
create ?message path
tries to create and lock the file at path
by creating a hard
link to path
.nfs_lock. The contents of path
will be replaced with a sexp
containing the caller's hostname and pid, and the optional message
.
Efforts will be made to release this lock when the calling program exits. But there
is no guarantee that this will occur under some types of program crash. If the
program crashes without removing the lock file an attempt will be made to clean up
on restart by checking the hostname and pid stored in the lockfile.
val create_exn : ?message:string -> string -> unit
create_exn ?message path
like create, but throws an exception when it fails to
obtain the lockval blocking_create : ?message:string -> string -> unit
blocking_create ?message path
like create, but sleeps for 1 second between lock
attempts and does not return until it succeedsval critical_section : ?message:string -> string -> f:(unit -> 'a) -> 'a
critical_section ?message path ~f
wrap function f
(including exceptions escaping
it) by first locking (using Lock_file.Nfs.create_exn
) and then unlocking the given lock
file.val get_hostname_and_pid : string -> (string * Core_kernel.Std.Pid.t) option
get_hostname_and_pid path
reads the lock file at path
and returns the hostname
and path in the file. Returns None
if the file cannot be read.val get_message : string -> string option
get_message path
reads the lock file at path
and returns the message in the
file. Returns None
if the file cannot be read.val unlock_safely : string -> unit
unlock_safely path
unlocks path
if path
was locked from the same host and the
pid in the file is not in the list of running processes.