MyNixOS website logo
Description

Shared memory and control structures for IPC.

Provides portable shared memory allocator and some synchronization primitives. Can be used for interprocess communication. Refer to README.md for further information.

interprocess

Hackage Haskell CI

Platform-independent interprocess communication.

This project provides a shared memory allocator and some synchronization primitives for Win32 and POSIX systems.

SharedObjectName

Foreign.SharedObjectName.SOName is a globally unique name that can be used to lookup shared objects across processes. Internally, it is a ForeignPtr to a C-string with a fixed length. The library provides Eq, Show, and Storable instances and helper functions to transfer SOName via pipes or by any other means.

SharedPtr

Foreign.SharedPtr provides a custom shared memory Allocator and a bunch of functions similar to vanilla Ptr. Memory allocation is implemented using POSIX mmap and Windows CreateFileMapping APIs. You can create as many allocators as you want (as your RAM can afford) and concurrently malloc and free memory in different processes using them. All functions of that module are wrappers on C functions from Foreign.SharedPtr.C. The latter can be used to pass the allocation functions as pointers (those C functions do not need Haskell runtime, thus can be used in unsafe callbacks).

Control.Concurrent.Process

Control.Concurrent.Process.* provide a few synchronization primitives trying to mirror the interface of Control.Concurrent.* modules for the IPC case. The behavior is slightly different due to IPC limitations. Internally, these use semaphore, mutexes, condition variables, and events from Win32/POSIX in a platform-dependent way.

TODO

  • [x] Foreign.SharedPtr -- malloc, realloc and free in the shared memory region that can be accessed by multiple processes.
  • [x] Semaphores
  • [x] Mutable variables (MVar-like) via Storable instance.
  • [ ] Control.Concurrent.Chan-like channels
  • [ ] More tests
  • [x] Ensure MVar waits are interruptible w.r.t. async exceptions on all platforms
  • [ ] Benchmarks

Think about it

There is an untested idea to address GHC stop-the-world GC problem:

  1. Create several instances of your program in different isolated processes using e.g. typed-process library.
  2. Establish shared memory and semaphore usage via this library
  3. Garbage collection events in one process do not affect another one at all. Profit!

The question is if the cost of IPC synchronization is lower than the added cost of collecting garbage in all parallel threads.

Metadata

Version

0.2.1.0

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