Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Zipster

Member Since 11 Mar 2000
Offline Last Active Yesterday, 12:05 PM
-----

Topics I've Started

Question regarding re-executing TBB tasks

26 October 2012 - 07:11 PM

I haven't been able to find much information on the net pertaining to a particular usage pattern of TBB tasks, wherein the task recycles itself so it can be executed again, in my case for some extended period of time:
class MyTask : public tbb::task
{
public:
	 virtual tbb::task* execute()
	 {
		  // ... do work ...
		  if (!isDone())
		  {
			   recycle_as_safe_continuation();
			   set_ref_count(1);

			   // Task starvation?
			   // return this;
		  }

		  return 0;
	 }

private:
	 bool isDone() const { ... }
}
My question is regarding the behavior or returning 0 versus this after recycling the task. The scheduling documentation states that returning a task bypasses the scheduler, and the thread will execute the returned task next. If all the active worker threads are executing such self re-executing tasks, and they all return themselves as the next task, does this mean that the scheduler will starve any/all other tasks in the ready pool(s) for as long as the active tasks aren't done? Alternatively, if I return 0 instead, are other threads free to steal the task, or does the non-zero refcount prevent that?

PARTNERS