MyNixOS website logo
Description

Strict MVars and TVars with invariant checking for IO and IOSim.

Strict MVar and TVar interfaces with invariant checking compatible with IO & io-sim.

Strict MVars and TVars with invariant checking

The strict-checked-vars package provides a strict interface to mutable variables (MVar) and TVars with invariant checking. It builds on top of strict-mvar, strict-stm and io-classes, and thus it provides the interface for MVar/TVar implementations for both IO and io-sim.

Checked and unchecked variants

There are currently two variant implementations of StrictTVars.

  • From strict-stm: Control.Concurrent.Class.MonadSTM.Strict.TVar
  • From strict-checked-vars: Control.Concurrent.Class.MonadSTM.Strict.TVar.Checked

Similarly, there are currently two variant implementations of StrictMVars.

  • From strict-mvar: Control.Concurrent.Class.MonadMVar.Strict
  • From strict-checked-vars: Control.Concurrent.Class.MonadMVar.Strict.Checked

The unchecked modules provide the simplest implementation of strict variables: a light wrapper around lazy variables that forces values to WHNF before they are put inside the variable. The checked module does the exact same thing, but it has the additional feature that the user can provide an invariant that is checked each time a new value is placed inside the variable. The checked modules are drop-in replacements for the unchecked modules, though invariants will be trivially true in that case. Non-trivial invariants can be set when creating a new variable.

newMVarWithInvariant :: MonadMVar m
                     => (a -> Maybe String)
                     -> a
                     -> m (StrictMVar m a)

newEmptyMVarWithInvariant :: MonadMVar m
                          => (a -> Maybe String)
                          -> m (StrictMVar m a)

newTVarWithInvariant :: (MonadSTM m, HasCallStack)
                     => (a -> Maybe String)
                     -> a
                     -> STM m (StrictTVar m a)

newTVarWithInvariantIO :: (MonadSTM m, HasCallStack)
                       => (a -> Maybe String)
                       -> a
                       -> m (StrictTVar m a)

Note: though the checked modules are drop-in replacements for the unchecked modules, the StrictMVar/StrictTVar types are distinct. This means we can't make mixed use of the checked and unchecked modules.

Guarantees for invariant checking on StrictMVars

Although all functions that modify a checked StrictMVar will check the invariant, we do not guarantee that the value inside the StrictMVar always satisfies the invariant. Instead, we do guarantee that if the StrictMVar is updated with a value that does not satisfy the invariant, an exception is thrown after the new value is written to the StrictMVar. The reason for this weaker guarantee is that leaving an MVar empty can lead to very hard to debug "blocked indefinitely" problems.

Metadata

Version

0.2.1.0

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows