Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cancellation to NIOThreadPool's async runIfActive #2679

Merged
merged 10 commits into from
Mar 25, 2024

Conversation

glbrntt
Copy link
Contributor

@glbrntt glbrntt commented Mar 12, 2024

Motivation:

To dedupe the thread pool from NIOFileSystem and NIOPosix, the one from NIOPosix needs to gain support for cancellation for its async runIfActive function.

Modification:

  • Generate a work ID when submitting async work to the pool, add that ID to a set in the cancellation handler
  • Check the existence of the ID in the cancel set when dequeuing the work

Result:

Queued NIOThreadPool tasks can be cancelled before they are run.

Motivation:

To dedupe the thread pool from NIOFileSystem and NIOPosix, the one from
NIOPosix needs to gain support for cancellation for its async
`runIfActive` function.

Modification:

- Generate a work ID when submitting async work to the pool, add that ID
  to a set in the cancellation handler
- Check the existence of the ID in the cancel set when dequeuing the
  work

Result:

Queued NIOThreadPool tasks can be cancelled before they are run.
@glbrntt glbrntt added the patch-version-bump-only For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1) label Mar 12, 2024
@glbrntt glbrntt marked this pull request as ready for review March 13, 2024 08:12
@glbrntt glbrntt requested a review from Lukasa March 13, 2024 08:13
@glbrntt glbrntt merged commit 1f5be71 into apple:main Mar 25, 2024
8 of 9 checks passed
@glbrntt glbrntt deleted the thread-pool branch March 25, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch-version-bump-only For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants