Portability | portable |
---|---|
Stability | experimental |
Maintainer | nominolo@googlemail.com |
This module implements "named locks".
A named lock is like a normal lock (MVar ()
) but is created
on demand. This is useful when you have a potentially infinite
number of resources that should not be used concurrently.
For example, in a web-server you might create a new lock for each database query so that the same query is only run once.
Named locks are allocated in a LockPool
. Names are arbitrary,
well-behaved instances of the Ord
class.
- newLockPool :: IO (LockPool name)
- data LockPool name
- grabNamedLock :: Ord name => LockPool name -> name -> IO ()
- releaseNamedLock :: Ord name => LockPool name -> name -> IO ()
- withNamedLock :: Ord name => LockPool name -> name -> IO a -> IO a
Creating Lock Pools
newLockPool :: IO (LockPool name)Source
Create a new, empty, lock pool.
Working with Named Locks
grabNamedLock :: Ord name => LockPool name -> name -> IO ()Source
Grab the lock with given name. Blocks until the lock becomes available.
releaseNamedLock :: Ord name => LockPool name -> name -> IO ()Source
Release the lock with the given name.
The released lock must have previously been grabbed via
grabNamedLock
.