mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
test: heavier test for lfqueue
This commit is contained in:
parent
12cb1f91d5
commit
7004fd4275
1 changed files with 29 additions and 0 deletions
|
|
@ -69,6 +69,7 @@ let pop_nonblock self : _ option =
|
||||||
assert_equal None (pop_nonblock q);
|
assert_equal None (pop_nonblock q);
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
(* basic concurrency check *)
|
||||||
(*$R
|
(*$R
|
||||||
let q = create ~dummy:0 () in
|
let q = create ~dummy:0 () in
|
||||||
|
|
||||||
|
|
@ -93,3 +94,31 @@ let pop_nonblock self : _ option =
|
||||||
List.iter Thread.join th;
|
List.iter Thread.join th;
|
||||||
assert_equal [5;4;3;2;1;0] !out
|
assert_equal [5;4;3;2;1;0] !out
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
(* heavier concurrency check *)
|
||||||
|
(*$R
|
||||||
|
let q = create ~dummy:0 () in
|
||||||
|
let n = 200_000 in
|
||||||
|
|
||||||
|
let gen _ =
|
||||||
|
for i = 1 to n do
|
||||||
|
push q i
|
||||||
|
done
|
||||||
|
in
|
||||||
|
|
||||||
|
let count = Atomic.make 0 in
|
||||||
|
let consume _ =
|
||||||
|
let missing = ref n in
|
||||||
|
while !missing > 0 do
|
||||||
|
match pop_nonblock q with
|
||||||
|
| Some x -> Atomic.incr count; decr missing
|
||||||
|
| None -> Thread.yield();
|
||||||
|
done
|
||||||
|
in
|
||||||
|
|
||||||
|
let th =
|
||||||
|
List.init 3 (Thread.create gen) @
|
||||||
|
List.init 3 (Thread.create consume) in
|
||||||
|
List.iter Thread.join th;
|
||||||
|
assert_equal ~printer:string_of_int (3*n) (Atomic.get count);
|
||||||
|
*)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue