- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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]
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page