Repository navigation
Run InvokeAsync and TryBeginInvoke work in submission order [patch] - #80
Merged
Merged
Conversation
DoInvokes drained the whole TryBeginInvoke queue before the task queue, so a thread that called InvokeAsync(A) and then TryBeginInvoke(B) saw B run first, and a follow-up could use a resource before it existed. Stamp every queued item, on both queues, with a shared Interlocked.Increment submission number taken before it is enqueued, and have DoInvokes merge the two queues by taking the lower-numbered head each time. TryBeginInvoke stays allocation-free: the number rides in the existing pre-allocated cell as a value tuple. Per-pump budgets, exception collection and inline task scheduling are unchanged. Document the cross-API ordering guarantee on TryBeginInvoke and DoInvokes, and repair the truncated TryBeginInvoke summary. Fixes #60 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CTnJ1xEhZzPB9o25LiPf2C
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Summary
DoInvokesemptied the wholeTryBeginInvokequeue before it touched the task queue. A thread that calledInvokeAsync(A)and thenTryBeginInvoke(B)therefore saw B run first. This implements the maintainer decision on the issue: keep submission order across both APIs.Interlocked.Incrementcounter before it is enqueued.DoInvokesmerges the two queues by always running whichever head has the lower number.TryBeginInvokestores the number in the existing pre-allocated cell as a value tuple, so it allocates nothing new.BeginInvokeFailedand theAggregateExceptionwork as before.TaskScheduler.Default.TryBeginInvokeandDoInvokesremarks now state the ordering guarantee across both APIs, and CLAUDE.md describes the merge.TryBeginInvokesummary had been cut off mid-sentence ("Attempts to queue an action / or allocating"), and is now complete.Tests
Two new tests in
TryBeginInvokeTests:InvokeAsyncThenTryBeginInvokeFromOneThreadRunInSubmissionOrderis the issue's acceptance test.InterleavedSubmissionsFromOneThreadRunInSubmissionOrdermixes both APIs in the order B1 A1 A2 B2 B3 A3.Results:
main, which producesB AandB1 B2 B3 A1 A2 A3.dotnet build -c Releasebuilds every target framework.Fixes #60
🤖 Generated with Claude Code
https://claude.ai/code/session_01CTnJ1xEhZzPB9o25LiPf2C
Generated by Claude Code