Skip to content

Commit a782481

Browse files
committed
- Renaming lockfree to Saturn
- Change data structures names for user-ergonomy (treiber_stack -> stack for example) - Uniformize queue interface and doc - Add CONTRIBUTING file and complete test/README.md
1 parent 6380a6d commit a782481

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+464
-284
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ tmp
66
*.install
77
*.native
88
*.byte
9-
*.merlin
9+
*.merlin
10+
*.json
11+
node_modules

.ocamlformat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
profile = default
2-
version = 0.23.0
2+
version = 0.25.1

.prettierrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"arrowParens": "avoid",
3+
"bracketSpacing": false,
4+
"printWidth": 80,
5+
"semi": false,
6+
"singleQuote": true,
7+
"proseWrap": "always",
8+
"overrides": [
9+
{
10+
"files": ["*.md"],
11+
"excludeFiles": "_build/*"
12+
}
13+
]
14+
}

CHANGES.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@ All notable changes to this project will be documented in this file.
44

55
## Not released
66

7-
* Add STM tests for current data structures (@lyrm, @jmid)
7+
- Rename data structures and package, add docs (@lyrm)
8+
- Add STM tests for current data structures (@lyrm, @jmid)
89

910
## 0.3.1
1011

11-
* Rework dscheck integration to work with utop (@lyrm)
12-
* Add OCaml 4 compatability (@sudha247)
13-
* Add STM ws_deque tests (@jmid, @lyrm)
12+
- Rework dscheck integration to work with utop (@lyrm)
13+
- Add OCaml 4 compatability (@sudha247)
14+
- Add STM ws_deque tests (@jmid, @lyrm)
1415

1516
## 0.3.0
1617

17-
* Add MPSC queue (@lyrm)
18-
* Add SPSC queue (@bartoszmodelski)
19-
* Add MPMC relaxed queue (@bartoszmodelski, @lyrm)
20-
* Add Michael-Scott Queue (@tmcgilchrist, @bartoszmodelski, @lyrm)
21-
* Add Treiber Stack (@tmcgilchrist , @bartoszmodelski, @lyrm)
22-
* Integrate model-checker (DSCheck) (@bartoszmodelski)
18+
- Add MPSC queue (@lyrm)
19+
- Add SPSC queue (@bartoszmodelski)
20+
- Add MPMC relaxed queue (@bartoszmodelski, @lyrm)
21+
- Add Michael-Scott Queue (@tmcgilchrist, @bartoszmodelski, @lyrm)
22+
- Add Treiber Stack (@tmcgilchrist , @bartoszmodelski, @lyrm)
23+
- Integrate model-checker (DSCheck) (@bartoszmodelski)
2324

2425
## v0.2.0
2526

26-
* Add Chase-Lev Work-stealing deque `Ws_deque`. (@ctk21)
27+
- Add Chase-Lev Work-stealing deque `Ws_deque`. (@ctk21)

CONTRIBUTING.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Contributing
2+
3+
Any contributions are appreciated! Please create issues/PRs to this repo.
4+
5+
### Maintainers
6+
7+
The current list of maintainers is as follows:
8+
9+
- @kayceesrk KC Sivaramakrishnan
10+
- @lyrm Carine Morel
11+
- @Sudha247 Sudha Parimala
12+
13+
### Guidelines for new data structures implementation
14+
15+
Reviewing most implementation takes times. Here are a few guidelines to make it
16+
easier for the reviewers :
17+
18+
- the issue tracker has a good list of data structures to choose from
19+
- implement a well know algorithm (there are a lot !)
20+
- from a _reviewed_ paper, ideally with proof of main claimed properties (like
21+
lock-freedom, deadlock freedom etc..)
22+
- from a well known and used concurrent library (like `java.util.concurrent`)
23+
- write tests with **multiple** domains. All the following tests are expected to
24+
be provided before a proper review is done, especially for implementations
25+
that do not come from a well-know algorithm :
26+
- unitary tests and `qcheck tests` : with one and multiple domains. If domains
27+
have specific roles (producer, consumer, stealer, etc..), it should appear
28+
in the tests.
29+
- tests using `STM` from `multicoretest`
30+
- (_optional_) `dscheck` tests (for non-blocking implementation)

README.md

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
# `lockfree` — Lock-free data structures for Multicore OCaml
2-
--------------------------------------------------------
1+
# `Saturn` — parallelism-safe data structures for Multicore OCaml
32

4-
A collection of Concurrent Lockfree Data Structures for OCaml 5. It contains:
3+
---
54

6-
* [Treiber Stack](src/treiber_stack.mli) A classic multi-producer multi-consumer stack, robust and flexible. Recommended starting point when needing LIFO structure.
7-
8-
* [Michael-Scott Queue](src/michael_scott_queue.mli) A classic multi-producer multi-consumer queue, robust and flexible. Recommended starting point when needing FIFO structure. It is based on [Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Queue Algorithms](https://www.cs.rochester.edu/~scott/papers/1996_PODC_queues.pdf).
5+
A collection of parallelism-safe data structures for OCaml 5. It contains:
96

10-
* [Chase-Lev Work-Stealing Deque](src/ws_deque.mli) Single-producer, multi-consumer dynamic-size double-ended queue (deque) (see [Dynamic circular work-stealing deque](https://dl.acm.org/doi/10.1145/1073970.1073974) and [Correct and efficient work-stealing for weak memory models](https://dl.acm.org/doi/abs/10.1145/2442516.2442524)). Ideal for throughput-focused scheduling using per-core work distribution. Note, [pop] and [steal] follow different ordering (respectively LIFO and FIFO) and have different linearization contraints.
11-
12-
* [SPSC Queue](src/spsc_queue.mli) Simple single-producer single-consumer fixed-size queue. Thread-safe as long as at most one thread acts as producer and at most one as consumer at any single point in time.
13-
14-
* [MPMC Relaxed Queue](src/mpmc_relaxed_queue.mli) Multi-producer, multi-consumer, fixed-size relaxed queue. Optimised for high number of threads. Not strictly FIFO. Note, it exposes two interfaces: a lockfree and a non-lockfree (albeit more practical) one. See the mli for details.
15-
16-
* [MPSC Queue](src/mpsc_queue.mli) A multi-producer, single-consumer, thread-safe queue without support for cancellation. This makes a good data structure for a scheduler's run queue. It is used in [Eio](https://github.com/ocaml-multicore/eio). It is a single consumer version of the queue described in [Implementing lock-free queues](https://people.cs.pitt.edu/~jacklange/teaching/cs2510-f12/papers/implementing_lock_free.pdf).
7+
| Name | What is it ? | Sources |
8+
| -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
9+
| [Treiber Stack](src/treiber_stack.mli) | A classic multi-producer multi-consumer stack, robust and flexible. Recommended starting point when needing LIFO structure | |
10+
| [Michael-Scott Queue](src/michael_scott_queue.mli) | A classic multi-producer multi-consumer queue, robust and flexible. Recommended starting point when needing FIFO structure. | [Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Queue Algorithms](https://www.cs.rochester.edu/~scott/papers/1996_PODC_queues.pdf) |
11+
| [Chase-Lev Work-Stealing Deque](src/ws_deque.mli) | Single-producer, multi-consumer dynamic-size double-ended queue (deque). Ideal for throughput-focused scheduling using per-core work distribution. Note, `pop` and `steal` follow different ordering (respectively LIFO and FIFO) and have different linearization contraints. | [Dynamic circular work-stealing deque](https://dl.acm.org/doi/10.1145/1073970.1073974) and [Correct and efficient work-stealing for weak memory models](https://dl.acm.org/doi/abs/10.1145/2442516.2442524)) |
12+
| [SPSC Queue](src/spsc_queue.mli) | Simple single-producer single-consumer fixed-size queue. Thread-safe as long as at most one thread acts as producer and at most one as consumer at any single point in time. | |
13+
| [MPMC Relaxed Queue](src/mpmc_relaxed_queue.mli) | Multi-producer, multi-consumer, fixed-size relaxed queue. Optimised for high number of threads. Not strictly FIFO. Note, it exposes two interfaces: a lockfree and a non-lockfree (albeit more practical) one. See the mli for details. | |
14+
| [MPSC Queue](src/mpsc_queue.mli) | A multi-producer, single-consumer, thread-safe queue without support for cancellation. This makes a good data structure for a scheduler's run queue. It is used in [Eio](https://github.com/ocaml-multicore/eio). | It is a single consumer version of the queue described in [Implementing lock-free queues](https://people.cs.pitt.edu/~jacklange/teaching/cs2510-f12/papers/implementing_lock_free.pdf). |
1715

1816
## Usage
1917

20-
lockfree can be installed from `opam`: `opam install lockfree`. Sample usage of
18+
`Saturn` can be installed from `opam`: `opam install saturn`. Sample usage of
2119
`Ws_deque` is illustrated below.
2220

2321
```ocaml
@@ -30,11 +28,26 @@ let () = Ws_deque.push q 100
3028
let () = assert (Ws_deque.pop q = 100)
3129
```
3230

31+
## Tests
32+
33+
Several kind of tests are provided for each data structure:
34+
35+
- unitary tests and `qcheck` tests: check semantics and expected behaviors with
36+
one and more domains;
37+
- `STM` tests: check _linearizability_ for two domains (see
38+
[multicoretests library](https://github.com/ocaml-multicore/multicoretests));
39+
- `dscheck`: checks _non-blocking_ property for as many domains as wanted (for
40+
two domains most of the time). See
41+
[dscheck](https://github.com/ocaml-multicore/dscheck).
42+
43+
See [test/README.md](test/README.md) for more details.
44+
3345
## Benchmarks
3446

35-
There is a number of benchmarks in `bench/` directory. You can run them with `make bench`. See [bench/README.md](bench/README.md) for more details.
47+
There is a number of benchmarks in `bench` directory. You can run them with
48+
`make bench`. See [bench/README.md](bench/README.md) for more details.
3649

3750
## Contributing
3851

39-
Contributions of more lockfree data structures appreciated! Please create
52+
Contributions of more parallelism-safe data structures appreciated! Please create
4053
issues/PRs to this repo.

bench/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
Benchmarks for lockfree
1+
Benchmarks for Saturn
22

3-
# General usage
3+
# General usage
44

5-
Execute `make bench` from root of the repository to run the standard set of benchmarks. The output is in JSON, as it is intended to be consumed by ocaml-benchmark CI (in progress).
5+
Execute `make bench` from root of the repository to run the standard set of
6+
benchmarks. The output is in JSON, as it is intended to be consumed by
7+
ocaml-benchmark CI (in progress).
68

7-
# Specific structures
9+
# Specific structures
810

911
Some benchmarks expose commandline interface targeting particular structures:
1012

11-
* [mpmc_queue.exe](mpmc_queue_cmd.ml)
13+
- [mpmc_queue.exe](mpmc_queue_cmd.ml)

bench/backoff.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type 'a t = { value : 'a; next : 'a t option Atomic.t }
55
let empty () = { value = Obj.magic (); next = Atomic.make None }
66

77
let push ~backoff_once t value =
8-
let b = Lockfree.Backoff.create () in
8+
let b = Saturn.Backoff.create () in
99
let new_head = ({ value; next = Atomic.make None } : 'a t) in
1010
let rec push_f () =
1111
let head = Atomic.get t.next in
@@ -18,7 +18,7 @@ let push ~backoff_once t value =
1818
push_f ()
1919

2020
let rec pop ?min_wait ~backoff_once t =
21-
let b = Lockfree.Backoff.create ?min_wait () in
21+
let b = Saturn.Backoff.create ?min_wait () in
2222
let head = Atomic.get t.next in
2323
match head with
2424
| None -> None
@@ -95,8 +95,8 @@ let run_artificial ~backoff_once () =
9595

9696
let bench ~run_type ~with_backoff () =
9797
let backoff_once =
98-
if with_backoff then Lockfree.Backoff.once
99-
else fun (_ : Lockfree.Backoff.t) -> ()
98+
if with_backoff then Saturn.Backoff.once
99+
else fun (_ : Saturn.Backoff.t) -> ()
100100
in
101101
let results = ref [] in
102102
let run =

bench/bench_spsc_queue.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
open Lockfree
1+
module Spsc_queue = Saturn.Single_prod_single_cons_queue
22

33
let item_count = 2_000_000
44

bench/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
(executables
22
(names main mpmc_queue_cmd)
3-
(libraries lockfree unix yojson))
3+
(libraries saturn unix yojson))

0 commit comments

Comments
 (0)