XTaskQueue: terminating a queue ends a dispatch waiting on it #239
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!239
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/239/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Maraco91 on GitHub · 2026-11-24 01:43 UTC · original
Maraco91:xtaskqueue/terminate-ends-dispatch→main· +82 −7 · 1 files · 1 commits · merged 2026-11-24 07:57 UTCWhat
A thread that pumps a manual port never comes back once its queue is terminated.
The documented way to run a manual port on a thread of one's own is
ended by
XTaskQueueTerminate(queue, ...), after which the thread is joined: terminating the queue makes the waiting dispatch return false (the GDK's own sample for manual threads says so in a comment; from memory, I could not open it here).Here
XTaskQueueDispatchwaits inPort::takeuntil the port has a task.XTaskQueueTerminatesets the queue's flag, which refuses every later submit withE_ABORT, and drains the port, but wakes no one, and the wait does not look at the flag. So after the termination nothing can ever wake that dispatch: the thread stays in it for good, and so does whoever joins the thread (a hang when the title tears a queue down). A dispatch that starts after the termination waits forever too.Now:
Port::takealso ends when its caller says no task will come;XTaskQueueDispatchpasses its queue'sterminatedflag, and returns false.XTaskQueueTerminatewakes the port's waiters after draining it. It does so after taking the port's lock, so a dispatch either sees the flag before it waits or is woken.The flag is the queue's, not the port's: a composite queue shares its ports, and a dispatch on another queue of the same port keeps waiting (checked below). The serialized port's own worker is unchanged (it passes "never").
I have not seen a title do this (I have no game files); middleware built on this API (libHttpClient ships in the package) runs dispatcher threads of this shape.
Tested
Windows 11 Pro 10.0.26200, rustc 1.98.1 (
x86_64-pc-windows-msvc), no game data, no GPU involved.New unit test
terminate_ends_a_waiting_dispatch: queue A with manual ports and a composite queue B on the same ports; a thread runs the loop above on A.INFINITEafter that returns false at once.Results:
main(d2a4bae) + the test only:cargo test -p victory-hle --lib terminate_ends_a_waitingfails at step 3 after the 5 s:still waiting on a terminated queue. Steps 1 and 2 pass.cargo test -p victory-hle --lib xasync::: 6 passed, 0 failed, in 0.23 s, three runs in a row.cargo clippy -p victory-hle --tests: nothing inxasync.rs.rustfmt --check: nothing in the lines changed (the file has existing differences atpending_withand near it).cargo xtask policy: 151 files ok.git merge-tree) with #132, #122 and #114, which change the same file: all clean. #132 adds its delayed callbacks toXTaskQueueTerminateafter the port loop; this adds the wake inside it.Not tested: a title run.
AI-assisted (Claude Code); the tests above were run on the machine described.
🤖 Generated with Claude Code
@jeremygold02 on GitHub · 2026-11-24 05:03 UTC · original
Thanks @Maraco91 for handling a dispatch that waits indefinitely on a manual queue. I tested the open PR at head
36d6a79595ff9c24930f7c881bd34d7fd56e425awith:Result: 1 passed, 0 failed (86 filtered out). The regression test starts a dispatcher blocked on queue A, terminates a composite queue B that shares A’s manual ports and verifies A continues dispatching work, then terminates A and verifies its blocked dispatcher exits. It also checks a dispatch started after termination returns immediately. This is a synthetic HLE unit test; it does not exercise a real title or host thread workload.
Code: xasync.rs.