dejafu-0.1.0.0: Overloadable primitives for testable, potentially non-deterministic, concurrency.

Safe HaskellNone
LanguageHaskell2010

Test.DejaFu.Deterministic.Schedule

Contents

Description

Deterministic scheduling for concurrent computations.

Synopsis

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.

type ThreadId = Int Source

Every live thread has a unique identitifer.

data NonEmpty a Source

The type of non-empty lists.

Constructors

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.

Utilities

makeNP :: Scheduler s -> Scheduler s Source

Turn a potentially pre-emptive scheduler into a non-preemptive one.

toList :: NonEmpty a -> [a] Source

Convert a NonEmpty to a regular non-empty list.