Skip to content

Commit d4677ad

Browse files
committed
Add buggy demo with OCaml5
Signed-off-by: Kakadu <Kakadu@pm.me>
1 parent b8cf716 commit d4677ad

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

examples/dune

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
(library
22
(name examples)
33
(modules
4-
(:standard \ main))
5-
(libraries progress unix logs logs.fmt logs.threaded fmt fmt.tty mtime
6-
mtime.clock.os vector threads.posix))
4+
(:standard \ main ocaml5))
5+
(libraries
6+
progress
7+
unix
8+
logs
9+
logs.fmt
10+
logs.threaded
11+
fmt
12+
fmt.tty
13+
mtime
14+
mtime.clock.os
15+
vector
16+
threads.posix))
717

818
(executable
919
(name main)
1020
(modules main)
1121
(libraries examples fmt))
22+
23+
(executable
24+
(name ocaml5)
25+
(modules ocaml5)
26+
(libraries progress domainslib))

examples/ocaml5.ml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
let domains_count = 2
2+
3+
let () =
4+
let xs = Array.init 100 (Fun.id) in
5+
let len = Array.length xs in
6+
let total = if len > 0 then len * (len - 1) / 2 else 0 in
7+
let bar ~total =
8+
let open Progress.Line in
9+
list
10+
[
11+
spinner ();
12+
bar total;
13+
count_to total;
14+
]
15+
in
16+
let useful_stuff _i _j = () in
17+
let module T = Domainslib.Task in
18+
let pool = T.setup_pool ~num_domains:domains_count () in
19+
Progress.with_reporter (bar ~total)
20+
(fun report ->
21+
T.run pool (fun () ->
22+
T.parallel_for pool ~start:0 ~finish:(len - 1) ~body:(fun i ->
23+
T.parallel_for pool ~start:(i + 1) ~finish:(len - 1)
24+
~body:(fun j ->
25+
report 1;
26+
useful_stuff i j))));
27+
T.teardown_pool pool

0 commit comments

Comments
 (0)