Safe Haskell | Unsafe |
---|
This is an internal module that provides the core parallel scheduler. It is not for end-users.
- data LVar a d
- state :: LVar a d -> a
- data HandlerPool
- newtype Par a = Par {}
- newtype ClosedPar = ClosedPar {
- exec :: SchedState -> IO ()
- yield :: Par ()
- newPool :: Par HandlerPool
- fork :: Par () -> Par ()
- forkHP :: Maybe HandlerPool -> Par () -> Par ()
- runPar :: Par a -> a
- runParIO :: Par a -> IO a
- runParLogged :: Par a -> IO ([String], a)
- withNewPool :: (HandlerPool -> Par a) -> Par (a, HandlerPool)
- withNewPool_ :: (HandlerPool -> Par ()) -> Par HandlerPool
- forkWithExceptions :: (IO () -> IO ThreadId) -> String -> IO () -> IO ThreadId
- quiesce :: HandlerPool -> Par ()
- quiesceAll :: Par ()
- logStrLn :: String -> Par ()
- dbgLvl :: Int
- newLV :: IO a -> Par (LVar a d)
- getLV :: LVar a d -> (a -> Bool -> IO (Maybe b)) -> (d -> IO (Maybe b)) -> Par b
- putLV :: LVar a d -> (a -> IO (Maybe d)) -> Par ()
- putLV_ :: LVar a d -> (a -> Par (Maybe d, b)) -> Par b
- freezeLV :: LVar a d -> Par ()
- freezeLVAfter :: LVar a d -> (a -> IO (Maybe (Par ()))) -> (d -> IO (Maybe (Par ()))) -> Par ()
- addHandler :: Maybe HandlerPool -> LVar a d -> (a -> IO (Maybe (Par ()))) -> (d -> IO (Maybe (Par ()))) -> Par ()
- liftIO :: IO a -> Par a
- toss :: MonadToss m => m Bool
Basic types and accessors
LVars are parameterized by two types:
- The first,
a
, characterizes the "state" of the LVar (i.e., the lattice element), and should be a concurrently mutable data type. That means, in particular, that only a transient snapshot of the state can be obtained in general. But the information in such a snapshot is always a lower bound on the current value of the LVar. - The second,
d
, characterizes the "delta" associated with aputLV
operation (i.e., the actual change, if any, to the LVar's state). In many cases such deltas allow far more efficient communication betweenputLV
s and blockedgetLV
s or handlers. It is crucial, however, that the behavior of aget
or handler does not depend on the particular choice ofputLV
operations (and hence deltas) that moved the LVar over the threshold. For simple data structures, the delta may just be the entire LVar state, but for, e.g., collection data structures, delta will generally represent a single insertion.
NFData (LVar a d) |
data HandlerPool Source
A HandlerPool
contains a way to count outstanding parallel computations that
are affiliated with the pool. It detects the condition where all such threads
have completed.
A monadic type constructor for parallel computations producing an answer a
.
This is the internal, unsafe type.
Safe, deterministic operations
newPool :: Par HandlerPoolSource
Create a handler pool.
forkHP :: Maybe HandlerPool -> Par () -> Par ()Source
Fork a child thread, optionally in the context of a handler pool.
runParIO :: Par a -> IO aSource
A version that avoids an internal unsafePerformIO
for calling
contexts that are already in the IO
monad.
runParLogged :: Par a -> IO ([String], a)Source
Debugging aid. Return debugging logs, in realtime order, in addition to the final result.
withNewPool :: (HandlerPool -> Par a) -> Par (a, HandlerPool)Source
Convenience function. Execute a Par
computation in the context of a fresh handler pool.
withNewPool_ :: (HandlerPool -> Par ()) -> Par HandlerPoolSource
Convenience function. Execute a Par
computation in the context of a fresh
handler pool, while ignoring the result of the computation.
forkWithExceptions :: (IO () -> IO ThreadId) -> String -> IO () -> IO ThreadIdSource
Exceptions that walk up the fork tree of threads.
Quasi-deterministic operations
quiesce :: HandlerPool -> Par ()Source
Block until a handler pool is quiescent.
quiesceAll :: Par ()Source
A global barrier.
Debug facilities
Debugging flag shared by several modules.
This is activated by setting the environment variable DEBUG=1..5
.
Unsafe operations; should be used only by experts to build new abstractions
:: LVar a d | the LVar |
-> (a -> Bool -> IO (Maybe b)) | already past threshold?
The |
-> (d -> IO (Maybe b)) | does |
-> Par b |
Do a threshold read on an LVar
:: LVar a d | the LVar |
-> (a -> IO (Maybe d)) | how to do the put, and whether the LVar's value changed |
-> Par () |
Update an LVar without generating a result.
:: LVar a d | the LVar |
-> (a -> Par (Maybe d, b)) | how to do the put, and whether the LVar's value changed |
-> Par b |
Update an LVar.
freezeLV :: LVar a d -> Par ()Source
Freeze an LVar (introducing quasi-determinism). It is the data structure implementor's responsibility to expose this as quasi-deterministc.
:: LVar a d | the LVar of interest |
-> (a -> IO (Maybe (Par ()))) | initial callback |
-> (d -> IO (Maybe (Par ()))) | subsequent callbacks: updates |
-> Par () |
Freeze an LVar after a given handler quiesces.
:: Maybe HandlerPool | pool to enroll in, if any |
-> LVar a d | LVar to listen to |
-> (a -> IO (Maybe (Par ()))) | initial callback |
-> (d -> IO (Maybe (Par ()))) | subsequent callbacks: updates |
-> Par () |
Add a handler to an existing pool.