mvar-lock-0.1.0.1: A trivial lock based on MVar.

Safe HaskellSafe
LanguageHaskell2010

Control.Concurrent.MVarLock

Description

Using an MVar () as a lock is a common pattern. This module just wraps that up into some functions with nice names that make the pattern explicit.

Synopsis

Documentation

data Lock Source #

A lock that can be exclusively acquired with acquireLock.

newLock :: IO Lock Source #

Create a new lock.

acquireLock :: Lock -> IO () Source #

Block until the lock is available, then grab it. Something that acquires the lock should at some point subsequently relinquish it with releaseLock. Consider using withLock instead unless you need more fine-grained control.

releaseLock :: Lock -> IO () Source #

Release a lock that you have previously acquired with acquireLock.

withLock :: Lock -> IO a -> IO a Source #

Acquire the lock, perform some action while the lock is held, then release the lock. You can use this instead of manually calling acquireLock and releaseLock.