Skip to content

Commit cae8514

Browse files
Merge pull request #40 from fabbing/tsan_warnings
Avoid TSan warning in the test-suite
2 parents 1df80e9 + 30e7f78 commit cae8514

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

test/qcheck_mpsc_queue.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ let tests_one_consumer_two_producers =
434434

435435
let multi_push lpush =
436436
Semaphore.Counting.acquire sema;
437-
while Semaphore.Counting.get_value sema <> 0 do
437+
while Semaphore.Counting.try_acquire sema do
438+
Semaphore.Counting.release sema;
438439
Domain.cpu_relax ()
439440
done;
440441
try
@@ -505,7 +506,8 @@ let tests_one_consumer_two_producers =
505506

506507
let guard_push lpush =
507508
Semaphore.Counting.acquire sema;
508-
while Semaphore.Counting.get_value sema <> 0 do
509+
while Semaphore.Counting.try_acquire sema do
510+
Semaphore.Counting.release sema;
509511
Domain.cpu_relax ()
510512
done;
511513
let closed_when_pushing =
@@ -532,7 +534,8 @@ let tests_one_consumer_two_producers =
532534
(* Waiting to make sure the producers have time to
533535
start. However, as the consumer will [pop] until one of
534536
the producer closes the queue, it is not a requirement to wait here. *)
535-
while Semaphore.Counting.get_value sema <> 0 do
537+
while Semaphore.Counting.try_acquire sema do
538+
Semaphore.Counting.release sema;
536539
Domain.cpu_relax ()
537540
done;
538541

test/qcheck_ws_deque.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ let tests_one_producer_two_stealers =
237237
let multiple_steal deque nsteal =
238238
Semaphore.Counting.acquire sema;
239239
let res = Array.make nsteal None in
240-
while Semaphore.Counting.get_value sema <> 0 do
240+
while Semaphore.Counting.try_acquire sema do
241+
Semaphore.Counting.release sema;
241242
Domain.cpu_relax ()
242243
done;
243244
for i = 0 to nsteal - 1 do

test/test_ws_deque.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ let test_push_and_steal () =
3131
Array.iter Domain.join domains;
3232
print_string "test_push_and_steal: ok\n"
3333

34+
let tailrec_concat l1 l2 = List.rev_append (List.rev l1) l2
35+
3436
let test_concurrent_workload () =
3537
(* The desired number of push events. *)
3638
let n = ref 100000 in
@@ -109,8 +111,10 @@ let test_concurrent_workload () =
109111
in
110112
assert (npushed = npopped + nstolen);
111113
let sort xs = List.sort compare xs in
112-
let stolen = Array.fold_left (fun accu stolen -> accu @ stolen) [] stolen in
113-
assert (sort pushed = sort (popped @ stolen));
114+
let stolen =
115+
Array.fold_left (fun accu stolen -> tailrec_concat accu stolen) [] stolen
116+
in
117+
assert (sort pushed = sort (tailrec_concat popped stolen));
114118
(* Print a completion message. *)
115119
Printf.printf
116120
"test_concurrent_workload: ok (pushed = %d, popped = %d, stolen = %d)\n"

0 commit comments

Comments
 (0)