-
Notifications
You must be signed in to change notification settings - Fork 31
Add simple examples for MS queue #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nikochiko
wants to merge
37
commits into
ocaml-multicore:main
Choose a base branch
from
nikochiko:examples
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 f07b56b
Add a wider range of examples
nikochiko e148857
Fix space leaks of Michael-Scott queue
polytypic cf89702
Run on 5.0.0 rather than 5.0.0~alpha0
polytypic 52f961e
Merge pull request #64 from ocaml-multicore/ms-queue-fix-and-tweaks
lyrm bd9b0b5
Fix the lock-free update of Michael-Scott style queue tail
polytypic 31d51fd
set QCHECK_MSG_INTERVAL to avoid clutter in CI logs
jmid 71c075c
Merge pull request #69 from jmid/set-qcheck-msg-interval
lyrm 7c5bd51
mark alcotest as a test dependency
Khady 9abc664
Merge pull request #70 from Khady/patch-1
Sudha247 42bd001
Better prints, concurrency with do_work function
nikochiko 2713111
Merge pull request #66 from ocaml-multicore/fix-ms-queue-tail-update
lyrm 970cd86
Add Random.self_init and run dune fmt
nikochiko ef6414f
Adopt OCaml Code of Conduct
Sudha247 a1e1613
Merge pull request #71 from ocaml-multicore/code-of-conduct
lyrm 087e287
Removing overlaps between github action and ocaml ci. Removing not wo…
lyrm 03d7fe7
Merge pull request #72 from lyrm/CI_changes
lyrm a17d1a3
Add multicoretest tests for current data structures.
lyrm 7195de5
Merge pull request #61 from lyrm/stm-test
lyrm d87aca1
Require qcheck-stm.0.2 and remove pin
jmid 6380a6d
Merge pull request #75 from jmid/remove-qcheck-stm-pin
lyrm a782481
- Renaming lockfree to Saturn
lyrm 1e7c41f
Merge pull request #67 from lyrm/dsds
Sudha247 67164e5
Refactor to separate lockfree from non-lockfree data structures.
lyrm fee6012
Merge pull request #76 from lyrm/refactoring
Sudha247 b485b74
Prepare release
Sudha247 8b9a688
Merge pull request #77 from ocaml-multicore/prepare-release-0.4
Sudha247 2aa31c2
Remove .merlin and .ocp-indent files.
lyrm b66baa9
Merge pull request #86 from lyrm/cleanup_dot_files
lyrm 0401757
Correct issue caused by saturn_lockfree module beeing named Lockfree.
lyrm 4fe464d
Add a barrier module in tests to replace the use of semaphores.
lyrm 46e1662
Format.
lyrm 682fbcf
Merge pull request #85 from lyrm/saturn_lockfree
lyrm a519b4b
Improve documentation and changes barrier implementation a bit for op…
lyrm 83253a5
Merge pull request #88 from lyrm/barrier_for_tests
lyrm e25194f
Merge commit 'refs/pull/59/head' of https://github.com/ocaml-multicor…
Sudha247 057c02b
Update examples to reflect lockfree -> saturn
Sudha247 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(executables | ||
(names michael_scott_queue) | ||
(libraries lockfree)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.