[Concurrency] Relax task-local mis-use prevention in task groups #73881
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.
We have a mechanism protecting task group child tasks from accessing values in "outer scope" if they are defined like this:
So to prevent this, today, we crash eagerly when we detect this.
The problem:
We crash to aggresively, also falsely triggering on this:
This patch solves this behavior by more precise runtime detecting of the specific problem situation -- we now crash inside the
addTask
and NOT inside thewithValue
.Future direction: We could start copying defensively when we notice the "bad situation" rather than just crash. @FranzBusch was arguing that behavior would be preferable -- because we cannot always control the shapes of APIs, and if someone were to offer a synchronous callback API and they had set a task local value inside a task group "by accident" without even knowing about it, today we would crash - causing weird non-local interactions.
I'll see if I can pull off the copying "only when we have to in the bad-bad and rare case".
resolves rdar://127156303