https://github.com/ocaml-multicore/picos
- It is an interface:
Libraries & Applications '' Schedulers ''
https://github.com/ocaml-multicore/picos
Libraries & Applications '' Schedulers ''
Let me first quote a paragraph from the Memory Representation of Values (with my emphasis):
Obj is an undocumented module that exposes the internals of the OCaml compiler and runtime. It is very useful for
Currently OCaml 5 provides a Domain.DLS module for domain-local storage.
Unfortunately,
there is no corresponding Thread.TLS for (sys)thread-local storage, and
the current implementation of Domain.DLS is not thread-safe.
For a long time OCaml has supported lightweight threads exposed via the Thread module. These threads are often called “systhreads”, but I will simply call them “threads” in this post.
The OCaml Stdlib also provides many mutable data structures such as Hashtbl, Queue, and Stack. As the documentation alerts, none of these are thread-safe.
(* Copyright (c) 2023 Vesa Karvonen | |
Permission to use, copy, modify, and/or distribute this software for any | |
purpose with or without fee is hereby granted, provided that the above | |
copyright notice and this permission notice appear in all copies. | |
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | |
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | |
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | |
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
Any functional data structure can be turned into a lock-free data structure by
wrapping it inside an Atomic
. For example, consider the following set
implementation:
module Identity_set : sig
type 'a t
val empty : 'a t
title |
---|
k-CAS for sweat-free concurrent programming |
Vesa Karvonen
The kcas
library currently uses
the GKMZ algorithm for
Efficient Multi-word Compare and Swap or
MCAS aka k-CAS. This is a nearly optimal algorithm for MCAS as it requires only
k + 1
CAS operations.
The new library API also provides a transactional API for using the algorithm. For example, suppose one would create the following shared memory locations: