Skip to content

Rejecting a task and adding it back to the queue? #105

@BrodyHiggerson

Description

@BrodyHiggerson

Another API / design creator blessing question for you.

In my existing task system, there is the concept of inter-task dependencies same as in enkiTS, but I also support read/write dependency declarations, where the task processing algorithm first attempts to satisfy the dependencies, and then all jobs that have task dependencies solved are put into a queue where they 'fight' to grab their read/write deps. It's not possible to know in advance which will win and imo it's not practical or worth trying to 'solve' that entire tree, instead we let it happen at runtime.

An example, called regularly, e.g. when a task completes and pulls in any dependent tasks that are unblocked. It's messy but more of an illustration.

void TickGraph::ReadyContendingJobsIfPossible()
{
// lock here ...
	static thread_local std::vector<TickJob*> contendeds;
	contendeds.reserve(128);

	{
		TickJob* contendingJob;
		while (contendingTickQueue_.try_pop(contendingJob))
		{
			if (impl_->typeDepTracker_.TryPushNode(contendingJob->node_)) // check against read/write dependencies
			{
				ExecuteJob(contendingJob);
			}
			else
			{
				contendeds.push_back(contendingJob); // we failed, so prepare to put the job back into the contending queue
			}
		}
	}

	for (TickJob* contended : contendeds)
	{
		MoveToContending(contended); // put it back in for next time
	}
	contendeds.clear();

// unlock here ...
}

I'm not trying to replicate this exactly but just giving context. I could imagine maybe in TaskScheduler::TryRunTask, in the block when bHaveTask is true, I add a call to some optional callback that checks if the task is actually allowed (defaulting to true), and if not, it calls AddTaskSetToPipe to put it back into circulation and early-outs. Not sure how I feel about the task going back into the end of the pipe, but maybe that's fine. Would also need to figure out a way to do it for Pinned tasks too.

Interested in any insights you might have from a canonical design/API POV, and I may have missed something that would help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions