- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I want to exclude main thread. I have a longrunning work that should run independent of main thread. Also, the longrunning work has to work by splitting it multiple tasks. I have tried to create a root task and enqueue it. Afterwards, the root task spawned the child tasks.
For example,
longtask *root_task = new(task::allocate_root())longtask();
task::enqueue(*root_task);
class longtask
{
task* execute()
{
set_ref_count(m_task_count + 1);
for(int i = 0; i < m_task_count; ++i)
{
spawn(*new(allocate_child())task_func(m_func, m_data, i, m_task_count));
}
wait_for_all();
}
}
Why doesn't it work? It works when I create explicitly worker thread(The worker thread spawns the childs and calls wait_for_all, there is no enqueue). So Main thread or another explicitly created worker thread can spawn childs only?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Did you mean that parent task doesn't wait child tasks' completion, and ready to continue?
It implies that you cannot use spawn with wait_for_all(). You may search detail in TBB's doc by using word "Continuation Passing".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
First of all, I thank you very much for your comment. After reading your answer, I examined again the given code. I realized that the problem was in a different place which a multi-thread programming mistake was in. Normally, the code above works. Anyway, I could not have realized this mistake without your answer :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"It implies that you cannot use spawn with wait_for_all()."
Huh? (as they say...)

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page