Safe Haskell | None |
---|---|
Language | Haskell2010 |
Deterministic scheduling for concurrent computations.
- type Scheduler s = s -> Maybe (ThreadId, ThreadAction) -> NonEmpty (ThreadId, NonEmpty Lookahead) -> (ThreadId, s)
- type ThreadId = Int
- data NonEmpty a = a :| [a]
- randomSched :: RandomGen g => Scheduler g
- roundRobinSched :: Scheduler ()
- randomSchedNP :: RandomGen g => Scheduler g
- roundRobinSchedNP :: Scheduler ()
- makeNP :: Scheduler s -> Scheduler s
- toList :: NonEmpty a -> [a]
Documentation
type Scheduler s = s -> Maybe (ThreadId, ThreadAction) -> NonEmpty (ThreadId, NonEmpty Lookahead) -> (ThreadId, s) Source
A Scheduler
maintains some internal state, s
, takes the
ThreadId
of the last thread scheduled, or Nothing
if this is
the first decision, and the list of runnable threads along with
what each will do in the next steps (as far as can be
determined). It produces a ThreadId
to schedule, and a new state.
Note: In order to prevent computation from hanging, the runtime will assume that a deadlock situation has arisen if the scheduler attempts to (a) schedule a blocked thread, or (b) schedule a nonexistent thread. In either of those cases, the computation will be halted.
The type of non-empty lists.
a :| [a] |
Pre-emptive
randomSched :: RandomGen g => Scheduler g Source
A simple random scheduler which, at every step, picks a random thread to run.
roundRobinSched :: Scheduler () Source
A round-robin scheduler which, at every step, schedules the
thread with the next ThreadId
.
Non pre-emptive
randomSchedNP :: RandomGen g => Scheduler g Source
A random scheduler which doesn't pre-empt the running thread. That is, if the last thread scheduled is still runnable, run that, otherwise schedule randomly.
roundRobinSchedNP :: Scheduler () Source
A round-robin scheduler which doesn't pre-empt the running thread.