A lock is in one of two states: "locked" or "unlocked".
Moduleconcurrent-extra-0.7.0.12Haskell98
Control.Concurrent.STM.Lock
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 ( ... )
- 1 type
- 9 values
- Packageconcurrent-extra-0.7.0.12
- Exports10
- LanguageHaskell98
- LicenceBSD-3-Clause
- SourceLock.hs
Creating locks
2 declarationsCreate a lock in the "unlocked" state.
Create a lock in the "locked" state.
Locking and unlocking
3 declarationsWhen the state is "locked"
acquirewillretrythe transaction.When the state is "unlocked"
acquirewill change the state to "locked".
A non-blocking acquire.
When the state is "unlocked"
tryAcquirechanges the state to "locked" and returnsTrue.When the state is "locked"
tryAcquireleaves the state unchanged and returnsFalse.
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
3 declarationsA 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.
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.
Querying locks
1 declarationDetermines if the lock is in the "locked" state.
Note that this is only a snapshot of the state. By the time a program reacts on its result it may already be out of date.