Repository navigation
Keep thread pool elapsed-time comparison signed - #7
Conversation
Co-authored-by: hez2010 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d5b99c9a1a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| (Environment.TickCount - Volatile.Read(ref threadPoolInstance._separated.lastExternalWorkItemTimeMs)) | ||
| > (int)ThreadPoolWorkQueue.DispatchQuantumMs); |
There was a problem hiding this comment.
Preserve TickCount wraparound for stale timestamps
When no external producer updates lastExternalWorkItemTimeMs for more than Int32.MaxValue milliseconds (about 24.9 days), this signed subtraction becomes negative until the next TickCount wrap. During that interval, every spurious dispatch at or below the threshold is incorrectly treated as recent external activity and enters the spinning Wait path rather than WaitNoSpin, potentially wasting CPU in long-running workloads driven entirely by worker-produced work. The publication race should be handled without losing the unsigned elapsed-time behavior, for example by using a timestamp representation or snapshot scheme that can distinguish a concurrent update from a genuinely stale value.
Useful? React with 👍 / 👎.
A concurrently published timestamp can make elapsed time negative; converting it to unsigned incorrectly treats recent external work as stale.
(uint)cast to preserve negative values.DispatchQuantumMslocally toint, keeping both operands signed without changing other uses.