From 7004fd4275d5d1eb52200b93d4bb7d92944bdb1a Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 22 Mar 2022 21:43:30 -0400 Subject: [PATCH] test: heavier test for lfqueue --- src/lf_queue/containers_lfqueue.ml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/lf_queue/containers_lfqueue.ml b/src/lf_queue/containers_lfqueue.ml index c2184448..116ab144 100644 --- a/src/lf_queue/containers_lfqueue.ml +++ b/src/lf_queue/containers_lfqueue.ml @@ -69,6 +69,7 @@ let pop_nonblock self : _ option = assert_equal None (pop_nonblock q); *) +(* basic concurrency check *) (*$R let q = create ~dummy:0 () in @@ -93,3 +94,31 @@ let pop_nonblock self : _ option = List.iter Thread.join th; 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); +*)