Skip to content

htsthread_wait() has no regression test - #760

Merged
xroche merged 1 commit into
masterfrom
test/htsthread-wait-selftest
Jul 27, 2026
Merged

htsthread_wait() has no regression test#760
xroche merged 1 commit into
masterfrom
test/htsthread-wait-selftest

Conversation

@xroche

@xroche xroche commented Jul 27, 2026

Copy link
Copy Markdown
Owner

#747 landed without a test, because #718 held htsselftest.c and tests/Makefile.am at the time. This is that test.

-#test=threadwait checks the contract from both ends: a htsthread_wait() placed right after a spawn joins that thread, and htsthread_wait_n(n) leaves n running instead of draining them. The gated threads used for the second half give up after ten seconds, so a wait that wrongly drains them fails the assertion rather than hanging the suite.

The first version of it was useless and that is worth recording. Spawning eight threads per round, it passed on the unfixed engine every single time: the earlier threads in the batch raise the counter while the rest are still being created, so the wait never sees the zero it needs to return early. One spawn per round opens that window about half the time, and sixteen rounds make it a certainty. Reverted to its pre-#752 state, src/htsthread.c now fails the test 10 runs out of 10, and the current tree passes 10 out of 10.

st_changes_race also drops the counter it kept for joining its own notifier threads. That workaround is what turned up the bug in the first place.

htsselftest.c and tests/Makefile.am were held by #718 while #747 was fixed, so
the thread-counting fix went in without a test. -#test=threadwait covers it
from both sides: a wait placed right after a spawn joins that thread, and
wait_n(n) leaves n running rather than draining them.

One spawn per round is what makes it bite. A batch gives the earlier threads
time to raise the counter themselves, which is why an eight-thread version
passed on the unfixed engine; one thread per round failed 10 runs out of 10.

The changes-race self-test can now drop the counter it kept because
htsthread_wait() could not be trusted to join.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <xroche@gmail.com>
@xroche
xroche merged commit 37fa549 into master Jul 27, 2026
22 checks passed
@xroche
xroche deleted the test/htsthread-wait-selftest branch July 27, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant