Safe Haskell | Trustworthy |
---|---|
Language | Haskell98 |
Automatic deadlock avoidance.
- class AbstractLock l where
- data BoxedAbstractLock where
- BoxedAbstractLock :: (AbstractLock l, Eq l, Hashable l, Typeable l) => l -> BoxedAbstractLock
- data LockSafetyException
- acquire :: BoxedAbstractLock -> [BoxedAbstractLock] -> IO ()
- release :: BoxedAbstractLock -> IO ()
- test :: IO ()
Documentation
class AbstractLock l where Source #
data BoxedAbstractLock where Source #
BoxedAbstractLock :: (AbstractLock l, Eq l, Hashable l, Typeable l) => l -> BoxedAbstractLock |
data LockSafetyException Source #
acquire :: BoxedAbstractLock -> [BoxedAbstractLock] -> IO () Source #
Acquire a lock. In order to implement deadlock avoidance, the function acquire
requires that all locks a thread may take while holding the given lock are annotated
in parameter possiblyAcq
.
While programs with locks have rare deadlock conditions, they have common lock use patterns in-thread. If we throw an exception whenever lock use patterns are not properly declared, all lock use patterns will show up in testing and can be annotated.
Complexity overview:
Let N = the number of locks.
Let K = the size of the largest directed component of the ownership graph.
Let C = the number of capabilities.
acquire
runs in O(K log N + K^3/C) time [provided C <= K].
release :: BoxedAbstractLock -> IO () Source #
Release a lock so acquired.
release
runs in O(log N) time.