Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
082fc44
Add a simple example of Michael_scott_queue
nikochiko Mar 1, 2023
f07b56b
Add a wider range of examples
nikochiko Mar 1, 2023
e148857
Fix space leaks of Michael-Scott queue
polytypic Mar 10, 2023
cf89702
Run on 5.0.0 rather than 5.0.0~alpha0
polytypic Mar 16, 2023
52f961e
Merge pull request #64 from ocaml-multicore/ms-queue-fix-and-tweaks
lyrm Mar 16, 2023
bd9b0b5
Fix the lock-free update of Michael-Scott style queue tail
polytypic Mar 20, 2023
31d51fd
set QCHECK_MSG_INTERVAL to avoid clutter in CI logs
jmid Mar 23, 2023
71c075c
Merge pull request #69 from jmid/set-qcheck-msg-interval
lyrm Mar 23, 2023
7c5bd51
mark alcotest as a test dependency
Khady Apr 3, 2023
9abc664
Merge pull request #70 from Khady/patch-1
Sudha247 Apr 3, 2023
42bd001
Better prints, concurrency with do_work function
nikochiko Apr 8, 2023
2713111
Merge pull request #66 from ocaml-multicore/fix-ms-queue-tail-update
lyrm May 9, 2023
970cd86
Add Random.self_init and run dune fmt
nikochiko May 10, 2023
ef6414f
Adopt OCaml Code of Conduct
Sudha247 May 11, 2023
a1e1613
Merge pull request #71 from ocaml-multicore/code-of-conduct
lyrm May 16, 2023
087e287
Removing overlaps between github action and ocaml ci. Removing not wo…
lyrm May 11, 2023
03d7fe7
Merge pull request #72 from lyrm/CI_changes
lyrm May 22, 2023
a17d1a3
Add multicoretest tests for current data structures.
lyrm Jan 12, 2023
7195de5
Merge pull request #61 from lyrm/stm-test
lyrm May 23, 2023
d87aca1
Require qcheck-stm.0.2 and remove pin
jmid Jun 2, 2023
6380a6d
Merge pull request #75 from jmid/remove-qcheck-stm-pin
lyrm Jun 7, 2023
a782481
- Renaming lockfree to Saturn
lyrm Feb 23, 2023
1e7c41f
Merge pull request #67 from lyrm/dsds
Sudha247 Jul 6, 2023
67164e5
Refactor to separate lockfree from non-lockfree data structures.
lyrm Jul 4, 2023
fee6012
Merge pull request #76 from lyrm/refactoring
Sudha247 Jul 10, 2023
b485b74
Prepare release
Sudha247 Jul 10, 2023
8b9a688
Merge pull request #77 from ocaml-multicore/prepare-release-0.4
Sudha247 Jul 10, 2023
2aa31c2
Remove .merlin and .ocp-indent files.
lyrm Jul 26, 2023
b66baa9
Merge pull request #86 from lyrm/cleanup_dot_files
lyrm Jul 26, 2023
0401757
Correct issue caused by saturn_lockfree module beeing named Lockfree.
lyrm Jul 26, 2023
4fe464d
Add a barrier module in tests to replace the use of semaphores.
lyrm Jul 5, 2023
46e1662
Format.
lyrm Jul 31, 2023
682fbcf
Merge pull request #85 from lyrm/saturn_lockfree
lyrm Jul 31, 2023
a519b4b
Improve documentation and changes barrier implementation a bit for op…
lyrm Jul 31, 2023
83253a5
Merge pull request #88 from lyrm/barrier_for_tests
lyrm Aug 1, 2023
e25194f
Merge commit 'refs/pull/59/head' of https://github.com/ocaml-multicor…
Sudha247 Sep 13, 2023
057c02b
Update examples to reflect lockfree -> saturn
Sudha247 Sep 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(executables
(names michael_scott_queue)
(libraries lockfree))
81 changes: 81 additions & 0 deletions examples/michael_scott_queue.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
open Lockfree.Michael_scott_queue

let n_domains = 4

let single_push_and_pop () =
let ms_q = create () in
let item = 1 in
push ms_q item;
Printf.printf "single_push_and_pop: pushed %d\n" item;
match pop ms_q with
| None -> failwith "single_push_and_pop: queue is empty"
| Some v -> Printf.printf "single_push_and_pop: popped %d\n" v

let do_work () =
(* do some work *)
for _ = 1 to Random.int 100_000 do
Domain.cpu_relax ()
done

let concurrent_push () =
let ms_q = create () in

(* push concurrently *)
let pusher id item _ =
do_work ();
push ms_q item;
Printf.printf "concurrent_push: pushed %d (pusher id: %d)\n" item id
in
let domains = Array.init n_domains (fun i -> Domain.spawn (pusher i (i+1))) in
Array.iter Domain.join domains

let concurrent_pop () =
let ms_q = create () in

(* push sequentially *)
for i = 1 to n_domains do
push ms_q i
done;

(* pop concurrently *)
let popper id _ =
do_work ();
match pop ms_q with
| None -> failwith "concurrent_pop: list is empty"
| Some v -> Printf.printf "concurrent_pop: popped %d (popper id: %d)\n" v id
in
let domains = Array.init n_domains (fun i -> Domain.spawn (popper i)) in
Array.iter Domain.join domains

let concurrent_push_and_pop () =
let ms_q = create () in

(* push and pop, both concurrently *)
let pusher id item _ =
do_work ();
push ms_q item;
Printf.printf "concurrent_push_and_pop: pushed %d (pusher id: %d)\n" item id
in
let rec pop_one id _ =
do_work ();
match pop ms_q with
| None -> pop_one id () (* keep trying until an item is popped *)
| Some v -> Printf.printf "concurrent_push_and_pop: popped %d (popper id: %d)\n" v id
in

(* n_domains/2 pushers, n_domains/2 poppers concurrently *)
let popper_domains =
Array.init (n_domains / 2) (fun i -> Domain.spawn (pop_one i))
in
let pusher_domains =
Array.init (n_domains / 2) (fun i -> Domain.spawn (pusher i (i+1)))
in
Array.iter Domain.join (Array.append pusher_domains popper_domains)

let main () =
single_push_and_pop ();
concurrent_push ();
concurrent_pop ();
concurrent_push_and_pop ()

let _ = main ()