dejafu

Overloadable primitives for testable, potentially non-deterministic, concurrency.

https://github.com/barrucadu/dejafu

Version on this page:0.2.0.0@rev:1
LTS Haskell 22.14:2.4.0.5
Stackage Nightly 2024-03-28:2.4.0.5
Latest on Hackage:2.4.0.5

See all snapshots dejafu appears in

MIT licensed by Michael Walker
Maintained by [email protected]
This version can be pinned in stack with:dejafu-0.2.0.0@sha256:211cdfacd984ba6375aff5e48d893e91d4600d3f6bacbe106ff467b63eb8d15c,4705

[Déjà Fu is] A martial art in which the user's limbs move in time as well as space, […] It is best described as "the feeling that you have been kicked in the head this way before" -- Terry Pratchett, Thief of Time

Concurrency is nice, deadlocks and race conditions not so much. The Par monad family, as defined in abstract-par provides deterministic parallelism, but sometimes we can tolerate a bit of nondeterminism.

This package provides a class of monads for potentially nondeterministic concurrency, with an interface in the spirit of GHC's normal concurrency abstraction.

MonadConc with IO:

The intention of the MonadConc class is to provide concurrency where any apparent nondeterminism arises purely from the scheduling behaviour. To put it another way, a given computation, parametrised with a fixed set of scheduling decisions, is deterministic. This assumption is used by the testing functionality provided by Test.DejaFu.

Whilst this assumption may not hold in general when IO is involved, you should strive to produce test cases where it does.

Memory Model

The testing functionality supports a few different memory models, for computations which use non-synchronised CRef operations. The supported models are:

  • Sequential Consistency: A program behaves as a simple interleaving of the actions in different threads. When a CRef is written to, that write is immediately visible to all threads.

  • Total Store Order (TSO): Each thread has a write buffer. A thread sees its writes immediately, but other threads will only see writes when they are committed, which may happen later. Writes are committed in the same order that they are created.

  • Partial Store Order (PSO): Each CRef has a write buffer. A thread sees its writes immediately, but other threads will only see writes when they are committed, which may happen later. Writes to different CRefs are not necessarily committed in the same order that they are created.

If a testing function does not take the memory model as a parameter, it uses TSO.

See the README for more details.