package core_unix

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

This just uses flock. The main reason this module exists is that create won't let you release locks, so we need a new interface.

Another difference is that implementation is simpler because it omits some of the features, such as

1. Unlinking on exit. That seems unsafe. Consider the following scenario:

  • both a and b create and open the file
  • a locks, unlinks and unlocks it
  • b locks and stays in critical section
  • c finds that there is no file, creates a new one, locks it and enters critical section You end up with b and c in the critical section together!

2. Writing pid or message in the file. The file is shared between multiple processes so this feature seems hard to think about, and it already lead to weird code. Let's just remove it. You can still find who holds the file open by inspecting output of lsof.

type t
val lock_exn : ?lock_owner_uid:int -> ?exclusive:bool -> ?close_on_exec:bool -> unit -> lock_path:string -> [ `We_took_it of t | `Somebody_else_took_it ]

Raises an exception if taking the lock fails for any reason other than somebody else holding the lock. Optionally sets the lock owner to lock_owner_uid.

val unlock_exn : t -> unit

Raises an exception if this lock was already unlocked earlier.

OCaml

Innovation. Community. Security.