Community
cancel
Showing results for 
Search instead for 
Did you mean: 
AJ13
New Contributor I
83 Views

Bug in TBB With ref_count() ?

I'm really not sure if this is a bug or not, it seems to be. The following code causes an assertion (compiled without optimizations):

Assertion 1L<state() & (1L<<:ALLOCATED>Aborted

Here's the code:
#include
#include

#include

class HelloTask : public tbb::task
{
public:
HelloTask(int depth) : _depth(depth) { }
tbb::task* execute()
{
if(_depth == 0) return 0;

HelloTask& a = *new ( allocate_child() ) HelloTask(_depth - 1);
HelloTask& b = *new ( allocate_child() ) HelloTask(_depth - 1);

set_ref_count(ref_count() + 1);
spawn(a);
set_ref_count(ref_count() + 1);
spawn(b);

int tmp;
for(int i = 0; i < 1000000; ++i)
{
tmp = tmp*i;
}

set_ref_count(ref_count() + 1);
wait_for_all();

return 0;
}
private:
int _depth;

};


int main()
{
tbb::task_scheduler_init init;

HelloTask& a = *new ( tbb::task::allocate_root() ) HelloTask(10);
tbb::task::spawn_root_and_wait(a);

}

0 Kudos
2 Replies
RafSchietekat
Black Belt
83 Views

Once you spawn a child, you must not use set_ref_count() again; use allocate_additional_child_of() instead.
AJ13
New Contributor I
83 Views

Quoting - Raf Schietekat
Once you spawn a child, you must not use set_ref_count() again; use allocate_additional_child_of() instead.

Aha, thanks.
Reply