How to implement task dependency?
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.
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.