Use a condition variable to control busy threads in dispatch_apply test #93
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The dispatch_apply test sometimes fails in multicore machines. The
failed function is test_apply_contended which tests if dispatch_apply
can make progress and finish with N concurrent busy threads running,
where N is the number of CPUs. According to the testing log, it fails
because some busy threads already finish before dispatch_apply() is
invoked.
This happens because the test uses the ITERS_PER_SECOND variable to
control the number of iteration of the loop in the busy thread and
optimistically hope the execution time is long enough to complete
the test. But sometimes this hope fails when the testing machine has
greater computing power and more CPU cores.
Instead of using ITERS_PER_SECOND, which makes an assumption about the
computing power of the test machine, a condition variable is used to
control execution of busy threads. It makes sure the busy thread can
only finish after dispatch_apply completes.