crossbeam icon indicating copy to clipboard operation
crossbeam copied to clipboard

How to implement task dependency?

Open VictorTaelin opened this issue 3 years ago • 1 comments

I'm interested in using Crossbeam's work stealing deques on my functional runtime, but I have an issue of task dependency. On my program, tasks aren't independent, but they depend on each-other, in the sense that a task A should only be executed once tasks B and C are completed, for example. Crossbeam's deque, as implemented, would allow task A to be stolen before its dependencies are completed, which would be incorrect. Is there any obvious way to extend the work stealer with a notion of dependency? One way I can think of would be to have a steal_and_swap and a swap primitive, so that, when a task is stolen, we replace it with a wait task.

VictorTaelin avatar Oct 19 '22 05:10 VictorTaelin

Simply don’t put task A on the queue until B and C have completed. You can do this by having B and C share an atomic counter. Once either task B or C completes, it increments the counter. Once the counter reaches 2, it submits A to the queue.

zopsicle avatar Nov 12 '22 23:11 zopsicle