imperative-edsl-0.4.1: Deep embedding of imperative programs with code generation

Safe HaskellNone
LanguageHaskell2010

Language.Embedded.Concurrent

Description

Basic concurrency primitives.

Synopsis

Documentation

data ThreadId Source

Constructors

TIDEval ThreadId (Flag ()) 
TIDComp TID 

Instances

type ChanBound = Word16 Source

Maximum number of elements in some bounded channel.

data Chan t a Source

A bounded channel.

data ThreadCMD prog a Source

Instances

data ChanCMD exp prog a Source

Instances

HFunctor * * (ChanCMD exp) Source 
EvalExp exp => Interp (ChanCMD exp) IO Source 
type IExp (ChanCMD e) = e Source 
type IExp ((:+:) (* -> *) * (ChanCMD e) i) = e Source 

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

Fork off a computation as a new thread.

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

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

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

Forcibly terminate a thread, then continue execution immediately.

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

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

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

Wait for a thread to terminate.

newChan :: (VarPred (IExp instr) a, ChanCMD (IExp instr) :<: instr) => IExp instr ChanBound -> ProgramT instr 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 :: (VarPred (IExp instr) a, ChanCMD (IExp instr) :<: instr) => IExp instr ChanBound -> ProgramT instr m (Chan Closeable a) Source

readChan :: (VarPred (IExp instr) a, ChanCMD (IExp instr) :<: instr) => Chan t a -> ProgramT instr m (IExp instr 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 :: (VarPred (IExp instr) a, VarPred (IExp instr) Bool, ChanCMD (IExp instr) :<: instr) => Chan t a -> IExp instr a -> ProgramT instr m (IExp instr 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 (IExp instr) :<: instr => Chan Closeable a -> ProgramT instr 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.

lastChanReadOK :: (VarPred (IExp instr) Bool, ChanCMD (IExp instr) :<: instr) => Chan Closeable a -> ProgramT instr m (IExp instr Bool) Source

When readChan was last called on the given channel, did the read succeed? Always returns True unless closeChan has been called on the channel. Always returns True if the channel has never been read.