- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to set up my app where main() just spawns the root task, and then use that root task's execute to set up and drive the rest of the app. My very simple example is throwing an assertion on the number of child tasks. For something this simple, it has to be something I'm doing. Here's the simplest example I can construct that causes the assertion:
#include
#ifndef __TBB_task_scheduler_init_H
#include "tbb/task_scheduler_init.h"
#endif
#ifndef __TBB_task_H
#include "tbb/task.h"
#endif
#ifndef __TBB_tbb_thread_H
#include "tbb/tbb_thread.h"
#endif
using namespace tbb;
class MainAppTask : public task
{
public:
MainAppTask()
{
}
~MainAppTask()
{
}
task* execute()
{ // Overrides virtual function task::execute
set_ref_count(1);
std::cout << "\\n Hello from the root task";
double test = 0.0;
for (int i = 0; i < 1000000; i++)
{
test += i;
}
std::cout << "\\n Test is " << test;
return NULL;
}
};
int main()
{
//tbb::task_scheduler_init init(1);
tbb::task_scheduler_init anonymous;
MainAppTask& a = *new(task::allocate_root()) MainAppTask();
task::spawn_root_and_wait(a);
return 1;
}
The assertion appears after execute starts but before it's finished.
Damien
#include
#ifndef __TBB_task_scheduler_init_H
#include "tbb/task_scheduler_init.h"
#endif
#ifndef __TBB_task_H
#include "tbb/task.h"
#endif
#ifndef __TBB_tbb_thread_H
#include "tbb/tbb_thread.h"
#endif
using namespace tbb;
class MainAppTask : public task
{
public:
MainAppTask()
{
}
~MainAppTask()
{
}
task* execute()
{ // Overrides virtual function task::execute
set_ref_count(1);
std::cout << "\\n Hello from the root task";
double test = 0.0;
for (int i = 0; i < 1000000; i++)
{
test += i;
}
std::cout << "\\n Test is " << test;
return NULL;
}
};
int main()
{
//tbb::task_scheduler_init init(1);
tbb::task_scheduler_init anonymous;
MainAppTask& a = *new(task::allocate_root()) MainAppTask();
task::spawn_root_and_wait(a);
return 1;
}
The assertion appears after execute starts but before it's finished.
Damien
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Method execute() of your task has calls set_ref_count(1) but does not have any waiting method called.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh, duh. No child tasks are spawned in that execute, so the ref count is wrong. Thank you.

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