File tree Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -434,7 +434,8 @@ let tests_one_consumer_two_producers =
434
434
435
435
let multi_push lpush =
436
436
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;
438
439
Domain. cpu_relax ()
439
440
done ;
440
441
try
@@ -505,7 +506,8 @@ let tests_one_consumer_two_producers =
505
506
506
507
let guard_push lpush =
507
508
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;
509
511
Domain. cpu_relax ()
510
512
done ;
511
513
let closed_when_pushing =
@@ -532,7 +534,8 @@ let tests_one_consumer_two_producers =
532
534
(* Waiting to make sure the producers have time to
533
535
start. However, as the consumer will [pop] until one of
534
536
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;
536
539
Domain. cpu_relax ()
537
540
done ;
538
541
Original file line number Diff line number Diff line change @@ -237,7 +237,8 @@ let tests_one_producer_two_stealers =
237
237
let multiple_steal deque nsteal =
238
238
Semaphore.Counting. acquire sema;
239
239
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;
241
242
Domain. cpu_relax ()
242
243
done ;
243
244
for i = 0 to nsteal - 1 do
Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ let test_push_and_steal () =
31
31
Array. iter Domain. join domains;
32
32
print_string " test_push_and_steal: ok\n "
33
33
34
+ let tailrec_concat l1 l2 = List. rev_append (List. rev l1) l2
35
+
34
36
let test_concurrent_workload () =
35
37
(* The desired number of push events. *)
36
38
let n = ref 100000 in
@@ -109,8 +111,10 @@ let test_concurrent_workload () =
109
111
in
110
112
assert (npushed = npopped + nstolen);
111
113
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));
114
118
(* Print a completion message. *)
115
119
Printf. printf
116
120
" test_concurrent_workload: ok (pushed = %d, popped = %d, stolen = %d)\n "
You can’t perform that action at this time.
0 commit comments