Community
cancel
Showing results for 
Search instead for 
Did you mean: 
kevin8
Beginner
44 Views

Typo in TBB Reference

In the code fragment 10.8.2.2 the reference count of this is set to k. Shouldnt the reference count of the continuation be set to k instead? Thank you.

Quote TBB Reference:

10.8.2.2 Recycling Parent as a Child

This style is useful when the child inherits much of its state from a parent and the continuation does not need the state of the parent. The child must have the same type as the parent. In the example, C is the type of the continuation, and must derive from class task.

[cpp]task* T::execute() {
    if( not recursing any further ) {
        ...
        return NULL;
    } else {
        set_ref_count(k);
        // Construct continuation
        C& c = allocate_continuation();
        // Recycle self as first child
        task& tk = *new(c.allocate_child()) T(...); spawn(tk);
        task& tk-1 = *new(c.allocate_child()) T(...); spawn(tk-1);
        ...
        task& t2 = *new(c.allocate_child()) T(...); spawn(t2);
        // task t1 is our recycled self.
        recycle_as_child_of(c);
        update fields of *this to subproblem to be solved by t1
        return this;
    }
}
[/cpp]

0 Kudos
4 Replies
robert-reed
Valued Contributor II
44 Views

Actually, if you look at the diagram describing the use of allocate_continuation:

you'll see that it transfers the reference count that was associated with the parent to the freshly allocated continuation task. The sample is setting the reference count on the proper task to guarantee the reference count is treated properly.

RafSchietekat
Black Belt
44 Views

"you'll see that it transfers the reference count that was associated with the parent to the freshly allocated continuation task"
I don't see that (the continuation would be the rightmost task), so I am inclined to agree that it is a mistake in the example code, which seems to have been adapted incorrectly from the code in the previous section, about recycle_as_continuation.
robert-reed
Valued Contributor II
44 Views

Yup, I think you're right, Raf, and I was a little too hasty in assuming the example correct and seeing in that diagram justification for my misperception. Taking a more careful look at it, now I suspect that the Recycling Parent as Child example was a cut-and-paste job from the Recycling Parent as Continuation example without sufficient attention to which task in the new example becomes the parent.

ARCH_R_Intel
Employee
44 Views

Thanks for pointing out the problem. Yes, it's a cut-and-paste error by me.

I have attached an excerpt with the correction.

Reply