lock-file: Provide exclusive access to a resource using lock file.

[ bsd3, library, system ] [ Propose Tags ]

Provide exclusive access to a resource using lock file, which are files whose purpose is to signal by their presence that some resource is locked.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
pedantic

Pass additional warning flags including -Werror to GHC during compilation.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.5.0.0, 0.5.0.1, 0.5.0.2, 0.7.0.0
Change log ChangeLog.md
Dependencies base (>=4.5 && <4.8), data-default-class (>=0.0 && <0.2), directory (>=1.1 && <1.3), exceptions (>0.6 && <0.7), tagged-exception-core (>=2.0.0.0 && <3), transformers (>=0.3 && <0.5) [details]
License BSD-3-Clause
Copyright (c) 2013, 2014 Peter Trško
Author Peter Trsko
Maintainer peter.trsko@gmail.com
Revised Revision 1 made by PeterTrsko at 2016-07-17T16:21:02Z
Category System
Home page https://github.com/trskop/lock-file
Bug tracker https://github.com/trskop/lock-file/issues
Source repo head: git clone git://github.com/trskop/lock-file.git
this: git clone git://github.com/trskop/lock-file.git(tag 0.5.0.0)
Uploaded by PeterTrsko at 2014-12-24T00:02:27Z
Distributions NixOS:0.7.0.0
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 3925 total (22 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2014-12-24 [all 1 reports]

Readme for lock-file-0.5.0.0

[back to package description]

Lock File

Hackage BSD3 License

Description

Provide exclusive access to a resource using lock file, which are files whose purpose is to signal by their presence that some resource is locked.

Usage Example

Following example acquires lock file and then waits 1000000 micro seconds before releasing it. Note also that it is possible to specify retry strategy. Here we set it to No and therefore this code won't retry to acquire lock file after first failure.

module Main (main)
    where

import Control.Concurrent (threadDelay)
    -- From base package, but GHC specific.

import qualified Control.Monad.TaggedException as Exception (handle)
    -- From tagged-exception-core package.
    -- http://hackage.haskell.org/package/tagged-exception-core
import Data.Default.Class (Default(def))
    -- From data-default-class package, alternatively it's possible to use
    -- data-default package version 0.5.2 and above.
    -- http://hackage.haskell.org/package/data-default-class
    -- http://hackage.haskell.org/package/data-default
import System.IO.LockFile
    ( LockingParameters(retryToAcquireLock)
    , RetryStrategy(No)
    , withLockFile
    )


main :: IO ()
main = handleException
    . withLockFile lockParams lockFile $ threadDelay 1000000
  where
    lockParams = def
        { retryToAcquireLock = No
        }

    lockFile = "/var/run/lock/my-example-lock"

    handleException = Exception.handle
        $ putStrLn . ("Locking failed with: " ++) . show

This command line example shows that trying to execute two instances of example at the same time will result in failure of the second one.

$ ghc example.hs
[1 of 1] Compiling Main             ( example.hs, example.o )
Linking example ...
$ ./example & ./example
[1] 7893
Locking failed with: Unable to acquire lock file: "/var/run/lock/my-example-lock"
$ [1]+  Done                    ./example

Building options

  • -fpedantic (disabled by default)

    Pass additional warning flags including -Werror to GHC during compilation.