- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Anybody has an idea how to submit a task to a tbb scheduler, but prevent it from being executed until some further programmer-defined event (like func. call or something)?
Thanks
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That's completely senseless. Why you ever need that? It's like asking for how can I call a function and not call it at the same time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When execute method starts I first try to get a lock and if I can I do my things, release and exit.
If I cannot get a lock I want to recycle _this_/create identical task, put it back in queue and exit.
My problem is that the new/recycled task executes next rather than be put on the end of the queue.
It gets called multiple times while another task processes the region, this is exactly what I was trying to avoid. At the same time there are tasks in the queue that could process other regions.
Any idea what I do wrong? Are there any way to put the task explicitly on the end of the queue?
I could maintain my own FIFO queue and manually schedule tasks, but that is something I don't want to do for several reasons.
This is simplified code (creates identical task and spawns it):
task* RefineTask::execute ()
{
int h = region->hold.compare_and_swap(1, 0);
if (!h) { // success
processRegion(region);
// release
region->hold = 0;
} else { // region is being processed
// return this back to the queue
task &p = *parent();
RefineTask &t = *new(task::allocate_additional_child_of(p)) RefineTask(region);
p.spawn(t);
}
return NULL;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Generally speaking, don't involve TBB until you'redone waiting the way you already know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The latest open-source release of TBB has an implementation of std::condition_variable. It's in include/tbb/compat/condition_variable .
Though blocking a thread for a long time hurts the efficiency of the task paradigm. If using tasking, it might be better to use a pattern that defers execution of the task instead of blocking the thread, which of course was your original question.
Our new TBB Design Patterns document has some relevant patterns. To get it now, go to http://www.threadingbuildingblocks.org/ver.php?fid=151, and look for Design_Patterns.pdf . Chapters 8-10 may be relevant to your problem. Even though chapter 8 is called "GUI Thread", it is worth reading first because chapters 9 and 10 build upon the example there. The patterns in those chapter rely upon the new task::enqueue functionality in the latest open source release.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Also, I cannot enqueue a task I am recycling, can I?
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page