ConcurrentUtils-0.4.4.0: Concurrent utilities

Safe HaskellTrustworthy
LanguageHaskell98

Control.CUtils.Deadlock

Description

Automatic deadlock prevention.

Automatic deadlock detection is inefficient, and computations cannot be rolled back or aborted in general.

Instead, I prevent deadlocks before they happen.

Synopsis

Documentation

data Res t u where Source

The typical sequence that produces a deadlock is as follows:

  1. Thread 1 acquires lock A
  2. Thread 2 acquires lock B
  3. Thread 1 tries to acquire B
  4. Thread 2 tries to acquire A

Deadlock.

Standard deadlock detection intervenes after (4) has occurred. I intervene in a lock acquisition that is followed by an unsafe schedule (here at (2)). I suspend thread 2 until a safe schedule is guaranteed -- in this case until thread 1 relinquishes lock A.

The Res arrow.

Computations are built with these constructors (and the arrow interface). Pieces of the arrow that hold locks have to be finitely examinable, Locks have to be used with the Acq and Rel constructors.

Constructors

Lift :: Kleisli IO t v -> Res v u -> Res t u 
Acq :: MVar () -> Res t u -> Res t u 
Rel :: MVar () -> Res t u -> Res t u 
Fork :: Res t () -> Res t u -> Res t u 
Plus :: Res t v -> Res u v -> Res (Either t u) v 
Id :: Res t t 

liftK :: (t -> IO u) -> Res t u Source

lft :: IO v -> Res v u -> Res b u Source

acq :: MVar () -> Res u u Source

rel :: MVar () -> Res u u Source

fork :: Res t () -> Res t u -> Res t u Source

run :: Res t u -> t -> IO u Source

Use this to run computations built in the Res arrow.