| Maintainer | Bas van Dijk <v.dijk.bas@gmail.com> , Roel van Dijk <vandijk.roel@gmail.com> |
|---|
Control.Concurrent.STM.Lock
Description
This module provides an STM version of Control.Concurrent.Lock.
This module is intended to be imported qualified. We suggest importing it like:
import Control.Concurrent.STM.Lock ( Lock ) import qualified Control.Concurrent.STM.Lock as Lock ( ... )
Documentation
Creating locks
newAcquired :: STM Lock
Create a lock in the "locked" state.
Locking and unlocking
- When the state is "locked"
acquirewillretrythe transaction. - When the state is "unlocked"
acquirewill change the state to "locked".
tryAcquire :: Lock -> STM Bool
release changes the state to "unlocked" and returns immediately.
Note that it is an error to release a lock in the "unlocked" state!
Convenience functions
A convenience function which first acquires the lock and then performs the computation. When the computation terminates, whether normally or by raising an exception, the lock is released.
tryWith :: Lock -> IO α -> IO (Maybe α)
A non-blocking with. tryWith is a convenience function which first tries to
acquire the lock. If that fails, Nothing is returned. If it succeeds, the
computation is performed. When the computation terminates, whether normally or
by raising an exception, the lock is released and Just the result of the
computation is returned.