API Reference · Benchmarks · Stdlib Benchmarks
Saturn — Parallelism-Safe Data Structures for Multicore OCamlThis repository is a collection of concurrent-safe data structures for OCaml 5. It aims to provide an industrial-strength, well-tested (and possibly model-checked and verified in the future), well documented, and maintained concurrent-safe data structure library. We want to make it easier for Multicore OCaml users to find the right data structures for their uses.
You can learn more about the motivation behind Saturn
through the implementation of a lock-free stack here.
Saturn is published on opam and is distributed under the ISC license.
To use Saturn, you need OCaml 5.2.0 or later. While Saturn is compatible with OCaml 4.14, this is primarily for compatibility purposes, as parallelism-safe data structures are not required without OCaml 5. Note that versions of OCaml 5 prior to 5.2 are not supported due to bugs in the Atomic
module that affect the functionality of some data structures.
To install OCaml 5.2.0 yourself, first make sure you have opam 2.1 or later. You can run this command to check:
Then use opam to install OCaml 5.2.0:
If you want a later version, you can run the following line to get a list of all available compiler versions:
opam switch list-available
saturn
can be installed from opam
:
length
function. This ensures that the stack is memory-bounded.length
function is needed.length
function. This ensures that the queue is memory-bounded.length
function is needed.pop
and steal
operations follow different ordering (LIFO and FIFO) with distinct linearization constraints. It is a role-oriented data structure: most functions can't be used by all domains.Stdlib.Map
, it is an ordered collection.pop
functions returns a random value contained on the bag.Some data structures are available in two versions: a normal version and a more optimized but unsafe version. The unsafe version utilizes Obj.magic
in a way that may be unsafe with flambda2
optimizations.
The reason for providing the unsafe version is that certain optimizations require features that are currently not available in OCaml, such as arrays of atomics or atomic fields in records. We recommend using the normal version of a data structure unless its performance is not sufficient for your use case. In that case, you can try the unsafe version.
Currently, the following data structures have an unsafe version:
Single_cons_single_prod_unsafe
: a single consumer single producer lock-free queueQueue_unsafe
: a Michael-Scott lock-free queueBounded_queue_unsafe
: a lock-free bounded queue based on Michael-Scott queue algorithmHtbl_unsafe
: a lock-free hashtableThis part describes how to use the provided data structures, and more exactly, what not to do with them. Two main points are discussed:
Some provided data structures are designed to work with specific domain configurations. These restrictions optimize their implementation, but failing to respect them may compromise safety properties. These limitations are clearly indicated in the documentation and often reflected in the name of the data structure itself. For instance, a single-consumer queue must have only one domain performing pop
operations at any given time.
To learn more about it, see this document.
Composability refers to the ability to combine functions while preserving their properties. For Saturn data structures, the expected properties include atomic consistency (or linearizability) and progress guarantees, such as lock-freedom. Unfortunately, Saturn's data structures are not composable.
To learn more about it, see this document.
One of the many difficulties of implementating parallelism-safe data structures is that in addition to providing the same safety properties as sequental ones, they may also have to observe some liveness properties as well as additional safety properties specific to concurrent programming, like deadlock-freedom.
In addition to the expected safety properties, the main properties we want to test for are:
Here is a list of the tools we use to ensure them:
qcheck
tests check semantics and expected behaviors with one and more domains.STM
tests check linearisability for two domains (see multicoretests
library).dscheck
checks non-blocking property for as many domains as wanted (for two domains most of the time). See dscheck.See test/README.md for more details.
There are a number of benchmarks in bench
directory. You can run them with make bench
. See bench/README.md for more details.
Contributions are appreciated! If you intend to add a new data structure, please read this before.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4