Skip to content

Keep thread pool elapsed-time comparison signed - #7

Merged
hez2010 merged 1 commit into
thread-poolfrom
copilot/address-review-comment
Oct 19, 2026
Merged

hez2010 merged 1 commit into
thread-poolfrom
copilot/address-review-comment

Conversation

Copilot AI commented Oct 19, 2026

Copy link
Copy Markdown

A concurrently published timestamp can make elapsed time negative; converting it to unsigned incorrectly treats recent external work as stale.

  • Signed subtraction: Remove the elapsed-time (uint) cast to preserve negative values.
  • Signed comparison: Cast DispatchQuantumMs locally to int, keeping both operands signed without changing other uses.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T18:00:59.881092Z d5b99c9 Draft marked ready
🔒 Security Review ✅ Completed 2026-10-19T18:00:39.116967Z d5b99c9 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@hez2010
hez2010 merged commit 69a681e into thread-pool Oct 19, 2026
1 check passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +195 to +196
(Environment.TickCount - Volatile.Read(ref threadPoolInstance._separated.lastExternalWorkItemTimeMs))
> (int)ThreadPoolWorkQueue.DispatchQuantumMs);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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.

2 participants