Skip to content

[Concurrency] Correct isolation handling with default act and task exec #82942

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Jul 10, 2025

We did not properly account for default actor's isolation in our task executor forwarding and... this is quite unfortunate.

TODO: rebase it on top of #82913 which does the Task.immediate changes

@ktoso ktoso requested review from xedin and al45tair July 10, 2025 05:59
@ktoso ktoso force-pushed the wip-task-executor-bug-isolation branch 2 times, most recently from 599e5f3 to e475ee6 Compare July 10, 2025 10:25
@@ -461,6 +461,14 @@ public protocol TaskExecutor: Executor {
// work-scheduling operation.
@_nonoverride
func enqueue(_ job: consuming ExecutorJob)

#if !$Embedded
// Must implement this requirement in order
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfinished comment? ("in order…" to what?)

// Must implement this requirement in order
@_nonoverride
@available(StdlibDeploymentTarget 6.2, *)
func enqueue(_ job: consuming ExecutorJob, isolatedTo serialExecutor: UnownedSerialExecutor/*some SerialExecutor*/)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be an implementation of this in DispatchExecutor.swift? It's not obvious to me what the isolatedTo: argument actually does here, or how an executor implementation would use it. Maybe some doc comments might help?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So my current attempt was such that you'd have to forward it into
job.run(isolatedTo: serialExecutor, serialExecutor: self.asUnownedSerialExecutor() when you get the enqueue call on the task excecutor.

I'm going to give this another look if we maybe could enqueue on the SerialExecutor when we are a DefaultActor and there notice the task executor after we aquired the default actor lock 🤔

ktoso added 2 commits July 11, 2025 11:36
In preparation for removal. This spelling of Task.immediate was before
SE-review and was NOT accepted and therefore we should try to remove it
entirely.
We did not properly account for default actor's isolation in our task
executor forwarding and... this is quite unfortunate.

This PR also includes a Task.immediate API addition which I'll rip out
from this PR and send in independently as that's low risk and just
missing API, and the bug we may have to run through an evolution
amendment
@ktoso ktoso force-pushed the wip-task-executor-bug-isolation branch from e475ee6 to 6c97c5a Compare July 11, 2025 02:43
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