Skip to content

Commit 35a333d

Browse files
authored
Merge pull request #5 from bartoszmodelski/readme
Add a simple readme
2 parents 796469d + 9c72a76 commit 35a333d

File tree

5 files changed

+69
-3
lines changed

5 files changed

+69
-3
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
v0.1.0
2+
--------------------------
3+
4+
* Initial experimental release.

LICENSE.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (c) 2022
2+
3+
Permission to use, copy, modify, and/or distribute this software for any
4+
purpose with or without fee is hereby granted, provided that the above
5+
copyright notice and this permission notice appear in all copies.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# `dscheck` — tool for testing concurrent OCaml programs
2+
3+
Experimental model checker for testing concurrent algorithms based on [Dynamic Partial-Order Reduction for Model Checking Software](https://users.soe.ucsc.edu/~cormac/papers/popl05.pdf). At the core, `dscheck` runs each test numerous times, exhaustively trying every single interleaving of atomic operations. User-provided assertions are run at the end of every execution.
4+
5+
6+
# Usage
7+
8+
Lockfree can be installed from `opam`: `opam install dscheck`. Sample usage on a [naive counter](tests/test_naive_counter.ml) is shown below.
9+
10+
```ocaml
11+
module Atomic = Dscheck.TracedAtomic
12+
(* tested implementation needs to use dscheck's atomic module *)
13+
14+
let test_counter () =
15+
let counter = Atomic.make 0 in
16+
let incr () = Atomic.set counter (Atomic.get counter + 1) in
17+
Atomic.spawn incr;
18+
Atomic.spawn incr;
19+
Atomic.final (fun () -> Atomic.check (fun () -> Atomic.get counter == 2))
20+
```
21+
22+
This is a classic example of a race condition with two threads trying to increment a counter without synchronisation. When the race occurs, one of the updates is lost. `dscheck` finds the interleaving that leads to that:
23+
24+
```
25+
Found assertion violation at run 12:
26+
Process 0: start
27+
Process 0: get 1
28+
Process 1: start
29+
Process 1: get 1
30+
Process 0: set 1
31+
Process 1: set 1
32+
Fatal error: exception File "src/tracedAtomic.ml", line 266, characters 6-12: Assertion failed
33+
```
34+
35+
36+
# Contributions
37+
38+
Contributions are appreciated! Please create issues/PRs to this repo.
39+

tests/dune

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(executable
2-
(name test_list)
3-
(modules test_list)
1+
(executables
2+
(names test_list test_naive_counter)
3+
(modules test_list test_naive_counter)
44
(libraries dscheck))

tests/test_naive_counter.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Atomic = Dscheck.TracedAtomic
2+
3+
let test_counter () =
4+
let counter = Atomic.make 0 in
5+
let incr () = Atomic.set counter (Atomic.get counter + 1) in
6+
Atomic.spawn incr;
7+
Atomic.spawn incr;
8+
Atomic.final (fun () -> Atomic.check (fun () -> Atomic.get counter == 2))
9+
10+
let () = Atomic.trace test_counter

0 commit comments

Comments
 (0)