Safe Haskell | None |
---|---|

Language | Haskell2010 |

Basic concurrency primitives.

- data ThreadId
- type ChanBound = Word16
- data Chan t a
- data ThreadCMD fs a
- data ChanCMD fs a
- data Closeable
- data Uncloseable
- fork :: ThreadCMD :<: instr => ProgramT instr (Param2 exp pred) m () -> ProgramT instr (Param2 exp pred) m ThreadId
- forkWithId :: ThreadCMD :<: instr => (ThreadId -> ProgramT instr (Param2 exp pred) m ()) -> ProgramT instr (Param2 exp pred) m ThreadId
- asyncKillThread :: ThreadCMD :<: instr => ThreadId -> ProgramT instr (Param2 exp pred) m ()
- killThread :: (ThreadCMD :<: instr, Monad m) => ThreadId -> ProgramT instr (Param2 exp pred) m ()
- waitThread :: ThreadCMD :<: instr => ThreadId -> ProgramT instr (Param2 exp pred) m ()
- newChan :: (pred a, ChanCMD :<: instr) => exp ChanBound -> ProgramT instr (Param2 exp pred) m (Chan Uncloseable a)
- newCloseableChan :: (pred a, ChanCMD :<: instr) => exp ChanBound -> ProgramT instr (Param2 exp pred) m (Chan Closeable a)
- readChan :: (pred a, FreeExp exp, VarPred exp a, ChanCMD :<: instr, Monad m) => Chan t a -> ProgramT instr (Param2 exp pred) m (exp a)
- writeChan :: (pred a, FreeExp exp, VarPred exp Bool, ChanCMD :<: instr, Monad m) => Chan t a -> exp a -> ProgramT instr (Param2 exp pred) m (exp Bool)
- closeChan :: ChanCMD :<: instr => Chan Closeable a -> ProgramT instr (Param2 exp pred) m ()
- lastChanReadOK :: (FreeExp exp, VarPred exp Bool, ChanCMD :<: instr, Monad m) => Chan Closeable a -> ProgramT instr (Param2 exp pred) m (exp Bool)

# Documentation

A bounded channel.

HFunctor * * ((,) k ((,) k *)) (ThreadCMD k k) Source | |

HBifunctor * k ((,) k *) (ThreadCMD (k -> *) k) Source | |

(:<:) ((,) (* -> *) ((,) (k -> *) ((,) k1 *))) * (ThreadCMD (k -> *) k1) instr => Reexpressible k ((,) k *) (ThreadCMD (k -> *) k) instr Source | |

InterpBi ((,) k *) * (ThreadCMD (* -> *) k) IO (Param1 k pred) Source |

HFunctor k * ((,) (* -> *) ((,) (* -> Constraint) *)) (ChanCMD (k -> *)) Source | |

HBifunctor * * ((,) (* -> Constraint) *) (ChanCMD (* -> *)) Source | |

(:<:) ((,) (* -> *) ((,) (* -> *) ((,) (* -> Constraint) *))) * (ChanCMD (* -> *)) instr => Reexpressible * ((,) (* -> Constraint) *) (ChanCMD (* -> *)) instr Source | |

InterpBi ((,) (* -> Constraint) *) * (ChanCMD (* -> *)) IO (Param1 (* -> Constraint) pred) Source |

data Uncloseable Source

fork :: ThreadCMD :<: instr => ProgramT instr (Param2 exp pred) m () -> ProgramT instr (Param2 exp pred) m ThreadId Source

Fork off a computation as a new thread.

forkWithId :: ThreadCMD :<: instr => (ThreadId -> ProgramT instr (Param2 exp pred) m ()) -> ProgramT instr (Param2 exp pred) m ThreadId Source

Fork off a computation as a new thread, with access to its own thread ID.

asyncKillThread :: ThreadCMD :<: instr => ThreadId -> ProgramT instr (Param2 exp pred) m () Source

Forcibly terminate a thread, then continue execution immediately.

killThread :: (ThreadCMD :<: instr, Monad m) => ThreadId -> ProgramT instr (Param2 exp pred) m () Source

Forcibly terminate a thread. Blocks until the thread is actually dead.

waitThread :: ThreadCMD :<: instr => ThreadId -> ProgramT instr (Param2 exp pred) m () Source

Wait for a thread to terminate.

newChan :: (pred a, ChanCMD :<: instr) => exp ChanBound -> ProgramT instr (Param2 exp pred) m (Chan Uncloseable a) Source

Create a new channel. Writing a reference type to a channel will copy the
*reference* into the queue, not its contents.

We'll likely want to change this, actually copying arrays and the like into the queue instead of sharing them across threads.

newCloseableChan :: (pred a, ChanCMD :<: instr) => exp ChanBound -> ProgramT instr (Param2 exp pred) m (Chan Closeable a) Source

readChan :: (pred a, FreeExp exp, VarPred exp a, ChanCMD :<: instr, Monad m) => Chan t a -> ProgramT instr (Param2 exp pred) m (exp a) Source

Read an element from a channel. If channel is empty, blocks until there
is an item available.
If `closeChan`

has been called on the channel *and* if the channel is
empty, `readChan`

returns an undefined value immediately.

writeChan :: (pred a, FreeExp exp, VarPred exp Bool, ChanCMD :<: instr, Monad m) => Chan t a -> exp a -> ProgramT instr (Param2 exp pred) m (exp Bool) Source

Write a data element to a channel.
If `closeChan`

has been called on the channel, all calls to `writeChan`

become non-blocking no-ops and return `False`

, otherwise returns `True`

.

closeChan :: ChanCMD :<: instr => Chan Closeable a -> ProgramT instr (Param2 exp pred) m () Source

Close a channel. All subsequent write operations will be no-ops. After the channel is drained, all subsequent read operations will be no-ops as well.