ConcurrentUtils-0.4.5.0: Concurrent utilities

Safe HaskellTrustworthy
LanguageHaskell98

Control.CUtils.Deadlock

Contents

Description

Automatic deadlock avoidance.

Synopsis

Documentation

class AbstractLock l where Source #

Minimal complete definition

lock, unlock

Methods

lock :: l -> IO () Source #

unlock :: l -> IO () 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.

test :: IO () Source #

Test: The dining philosophers problem

Orphan instances

Show (MVar t) Source # 

Methods

showsPrec :: Int -> MVar t -> ShowS #

show :: MVar t -> String #

showList :: [MVar t] -> ShowS #

Hashable (MVar t) Source # 

Methods

hashWithSalt :: Int -> MVar t -> Int #

hash :: MVar t -> Int #