-
Notifications
You must be signed in to change notification settings - Fork 577
Description
For some kinds of problems / algorithms, spawning tasks into a scope is useful. It's unfortunate that each task needs a separate heap allocation. I've tried a few different approaches which I've documented here, but have returned to using Scope::spawn due to downsides of those approaches.
It seems like there could be a few options for changes / additions to the Scope::spawn API that might allow the heap allocation to be avoided.
One way would be to make the Scope generic over some type then allow pushing new work items of that type. Perhaps Scope wouldn't be the right name for that. It's probably more of a dynamically growable work queue where work items can add more work items and runs until all work is complete with no additional work items added.
Another approach might be to configure each scope with a work-item size. Spawned tasks would then need size and alignment <= that size, but could then be stored adjacent to one another in some internal storage within the scope.
Join can be used for some of these kinds of problems, but can end up pretty awkward and can easily result in stack overflows if you're not careful.