Skip to content

Broadcast when wait() releases the monitor, so a thread entering wakes - #21

Merged
atgreen merged 1 commit into
masterfrom
wait-broadcast
Oct 19, 2026
Merged

atgreen merged 1 commit into
masterfrom
wait-broadcast

Conversation

@atgreen

@atgreen atgreen commented Oct 19, 2026

Copy link
Copy Markdown
Owner

wait(J) (src/native/support.lisp) and wait0(J) (src/native/threads.lisp, the one JDK 21+ uses) give up the monitor and wake one thread with condition-notify, on the monitor's condition variable, which threads entering share with threads in wait(). When that wakeup lands on another wait(), that thread sees it is still in the wait set and goes back to sleep, and the thread entering stays asleep at a free monitor until the other wait times out.

This is the same lost wakeup #20 fixed in monitor-exit, so this makes both sites sb-thread:condition-broadcast as well. Every waiting loop already re-checks its condition (owner or wait-set membership), so the extra wakeups are harmless.

Checks: the new aaa/waitwake.java has a thread in wait(5000), a holder that enters and then calls wait(5000) itself, and a third thread blocked entering. Without the fix the third thread entered after ~5000 ms, three runs out of three (slow after 5000 ms); with it, OK three out of three. It also prints OK on the reference JVM. aaa/monitorwake.java still passes. I couldn't run make check-regression locally (no DejaGnu here), so CI's regression gate is the full check.

🤖 Generated with Claude Code

wait(J) and wait0(J) give up the monitor and wake one thread on its
condition variable, which threads entering share with threads in wait().
When that wakeup lands on another wait(), the thread entering sleeps at
the door of a free monitor until the other wait times out.  This is the
same lost wakeup PR #20 fixed in monitor-exit; broadcast here too.

The new aaa/waitwake.java enters after ~5000 ms without the fix (3/3)
and immediately with it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@atgreen
atgreen merged commit ec538ee into master Oct 19, 2026
2 checks passed
@atgreen
atgreen deleted the wait-broadcast branch October 19, 2026 23:03
atgreen added a commit that referenced this pull request Oct 20, 2026
PRs #19-#21 and #23-#27 added aaa/jitwake, monitorwake, waitwake,
zipfile, filestat, lazyloader, reflstatic, siblingloaders and childfirst.
check-regression.sh only fails on lost passes and new failures, so a new
test is not enforced until it is in the baseline.  Core suites now 528
expected passes, up from 501; no test changed state.

Generated with make check-regression at 2e5e6db; the Running lines keep
the existing baseline's paths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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