I'm currently studying the codebase to evaluate how useful a port of the deadlock resolution to async frameworks on different runtimes would be and am a bit confused on the purpose of nestingFactories.
From what I can tell they contain a set of JoinableTaskFactory of its ambient tasks. This is calculated whenever a JoinableTask is launched.
The publically visible call sites to code which consumes nestingFactories are SynchronizationContext.Post and SwitchToMainThread. The usage of nestingFactories seems to be that it will post to any UnderlyingSynchronizationContext in the hierarchy of ambient tasks.
So whats the point of all this effort? It is optimized to not allocate in the common case of only having a single JoinableTaskFactory, so obviously there is some issue with having multiple TaskFactories it tries to solve? There are two scenarios I can think of that lead to having multiple factories:
- Creating multiple instances of
JoinableTaskFactory for the same JoinableTaskContext (including JoinableTaskCollection)
- Creating multiple instances from distinct
JoinableTaskContext (different UI threads?)
Since UnderlyingSynchronizationContext forwards to the JoinableTaskContext the first case does not really solve any issues does it? It just posts multiple times to the same SC, so it actually is an unnecessary performance overhead if anything, isn't it? I'd have expected the set of nesting JoinableTaskContext to be stored, not the set of nesting JoinableTaskFactory.
If the factories are for different UI threads then I'm wondering if this code is even correct in the first place, why would it post to every underlying thread when targeting a specific JoinableTask? Doesn't this basically mean code can run on arbitrary threads which happen to be in the chain launching a JoinableTask?
So, any idea what the nesting factories code is there for? Any scenario it actually helps with?
I'm currently studying the codebase to evaluate how useful a port of the deadlock resolution to async frameworks on different runtimes would be and am a bit confused on the purpose of
nestingFactories.From what I can tell they contain a set of
JoinableTaskFactoryof its ambient tasks. This is calculated whenever aJoinableTaskis launched.The publically visible call sites to code which consumes
nestingFactoriesareSynchronizationContext.PostandSwitchToMainThread. The usage ofnestingFactoriesseems to be that it will post to anyUnderlyingSynchronizationContextin the hierarchy of ambient tasks.So whats the point of all this effort? It is optimized to not allocate in the common case of only having a single
JoinableTaskFactory, so obviously there is some issue with having multiple TaskFactories it tries to solve? There are two scenarios I can think of that lead to having multiple factories:JoinableTaskFactoryfor the sameJoinableTaskContext(includingJoinableTaskCollection)JoinableTaskContext(different UI threads?)Since
UnderlyingSynchronizationContextforwards to theJoinableTaskContextthe first case does not really solve any issues does it? It just posts multiple times to the same SC, so it actually is an unnecessary performance overhead if anything, isn't it? I'd have expected the set of nestingJoinableTaskContextto be stored, not the set of nestingJoinableTaskFactory.If the factories are for different UI threads then I'm wondering if this code is even correct in the first place, why would it post to every underlying thread when targeting a specific JoinableTask? Doesn't this basically mean code can run on arbitrary threads which happen to be in the chain launching a
JoinableTask?So, any idea what the nesting factories code is there for? Any scenario it actually helps with?