dougbinks / enkiTS

A permissively licensed C and C++ Task Scheduler for creating parallel programs. Requires C++11 support.
zlib License
1.66k stars 138 forks source link

Run all tasks of given priority (or higher) #86

Closed eugeneko closed 7 months ago

eugeneko commented 1 year ago

I am in need of something inbetween WaitforAll() and WaitforTask(nullptr, priority). In my pipeline, user code dumps a lot of tasks with highest priority and then makes sure they all completed (but not low priority background tasks!).

I struggle to port this behavior to enkiTS. Any hints?

dougbinks commented 1 year ago

This can be done with dependencies.

You create an ICompletable with dependencies on the tasks with high priorities, and then wait on that.

I should make this into an example, along with some more documentation.

eugeneko commented 1 year ago

I have some troubles following your advice.

Before I call AddTaskSetToPipe for my task, I do observerTask.SetDependency(internalTask->observerDependency_, internalTask).

Then I call WaitforTask(&observerTask) when all tasks are added.

However, I get the assert when I add second task as dependency: pTaskToRunOnCompletion_->GetIsComplete() is false, where pTaskToRunOnCompletion_ is my observerTask. I am doing something wrong, but I struggle to see what.

Maybe I cannot add another dependency when the first dependency is already running? It's not obvious why tho.

dougbinks commented 1 year ago

Maybe I cannot add another dependency when the first dependency is already running?

Yes, all dependencies must be added before they are run.

This is because the first task could complete before the second task was added, causing the dependent task to complete.

I am considering an approach to add dependencies dynamically to a dependent task, but this is not yet implemented.