TBB task allocation assertion

TBB task allocation assertion

foxcub's picture

I'm trying to traverse a tree via TBB tasks and continuations. The code is below. When I run the code it keeps aborting (frequently, although not always) with the following error:

Assertion t_next->state()==task::allocated failed on line 334 of file ../../src/tbb/custom_scheduler.h Detailed description: if task::execute() returns task, it must be marked as allocated

What can be causing this problem?

template
void
traverse_tree(NodeVisitor& nv)
{
TreeTraversal& tt = *(new(task::allocate_root()) TreeTraversal(nv));
task::spawn_root_and_wait(tt);
}

template
class TreeTraversal: public task
{
public:
struct Continuation;

public:
TreeTraversal(NodeVisitor nv_):
nv(nv_) {}

task* execute()
{
nv.pre();

Continuation* c = new(allocate_continuation()) Continuation(nv);
c->set_ref_count(nv.size());
for (size_t i = 0; i < nv.size(); ++i)
{
TreeTraversal& tt = *(new(c->allocate_child()) TreeTraversal(nv.child(i)));
spawn(tt);
}

if (!nv.size())
return c;

return NULL;
}

private:
NodeVisitor nv;
};

template
class TreeTraversal::Continuation: public task
{
public:
Continuation(NodeVisitor& nv_):
nv(nv_) {}
task* execute() { nv.post(); return NULL; }

private:
NodeVisitor nv;
};

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
foxcub's picture

Alexey Kukanov has solved the problem on StackOverflow.

Login to leave a comment.