Bug in TBB With ref_count() ?

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<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);

}

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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

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

Aha, thanks.

Leave a Comment

Please sign in to add a comment. Not a member? Join today