imperative-edsl-0.5: 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 fs a Source

Instances

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 

data ChanCMD fs a Source

Instances

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 

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.

lastChanReadOK :: (FreeExp exp, VarPred exp Bool, ChanCMD :<: instr, Monad m) => Chan Closeable a -> ProgramT instr (Param2 exp pred) m (exp 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.