MyNixOS website logo
Description

A thread-safe (STM) persistency interface for finite map types.

Changes in 0.3.*:

  • Added the TFiniteMap type to make type construction more convenient.

  • Added markAsDirty.

  • Fixed data corruption issues with Backend.Binary.

Changes in 0.2.*:

  • Improved error handling. Backend lookup-exceptions are now rethrown in the AdvSTM monad.

Changes in 0.1.*:

  • Added the binary serialization backend.

This library provides a thread-safe (STM) frontend for finite map types together with a backend interface for persistent storage. The TMap data type is thread-safe, since all access functions run inside an STM monad . Any type instantiating Data.Edison.Assoc.FiniteMapX (see EdisonAPI) can be used as a map type.

When a TMap is modified within an STM transaction, a corresponding backend IO-request is added using the onCommit hook (cf. stm-io-hooks package). To ensure consistency, the (Adv)STM monad runs these requests iff the transaction commits. Additional backends (e.g. HDBC) can be added by instantiating the class Backend.

Example:

Thread 1:

atomically $ do
  isMemb <- member 1 tmap
  when (not isMemb) $
    insert 1 "john doe" tmap

Thread 2:

atomically $ do
  v <- lookup 1 tmap
  -- ... do something with 'v'
  adjust (\_ -> "jd") 1 tmap

The function member will first check whether the key value '1' is in the map; if not, it sends a lookup-request to the persistent backend and then retries the transaction. Note that "sending a lookup-request" essentially means adding a call to the corresponding IO-function of the backend to the list of retry-IO actions. (This is done using the retryWith IO hook of the stm-io-package.)

If the value does not yet exist, function insert adds the key-value mapping to the TMap and sends an insert-request to the backend using the onCommit hook of the stm-io-package. Note that onCommit guarantees that the backend IO action is only executed iff the transaction commits. Any changes that were made to the TMap are invisible to other threads until the onCommit actions are run. Therefore, the threads will always observe a consistent state.

The module Data.TStorage provides a high level interface to TMap inspired by the TCache package ((C) Alberto Gomez Corona). It can store any type that has a key (i.e. is an instance of type class HasKey). See file Sample.hs for an example on how to use it.

Warning: This package is very experimental and the interface will probably change.

Metadata

Version

0.3.5

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • 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