Bug in documentation?

Bug in documentation?

I think there's a error in the tutorial document (http://cache-www.intel.com/cd/00/00/30/11/301132_301132.pdf). On page 57, it gives an example using recycling as a demonstration of how to sometimes avoid allocating other tasks, but then it goes and allocates all of the tasks anyway. I'm pretty sure that line 12 of that example, "FibTask& a = *new( c.allocate_child() ) FibTask(n-2,&c.x);", should be removed.

To test this, I typed up the example; the below code (with the given line commented out) works for me:
41. clover ~/tbb-tutorial-test: g++ -ltbb fib.cc
42. clover ~/tbb-tutorial-test: ./a.out

Does this seem right to anyone else? CPS stuff still makes my brain hurt so I'm not quite confident enough to actually file a bug report at this moment. ;-)

Edit: In case this wasn't clear, I think it also works if you leave the line in. Without knowing the internals of the task class and such it's possible that it's a memory leak, but nothing worse. However, it does sort of miss the point of the section, which is that by using the recycling framework you can avoid allocations.


#include "tbb/task.h"
#include "tbb/task_scheduler_init.h"

using namespace tbb;
using namespace std;

long SerialFib(long n) {
if(n<2) return n;
else return SerialFib(n-1)+SerialFib(n-2);

struct FibContinuation : public task {
long* const sum;
long x,y;

FibContinuation(long* sum_) : sum(sum_) {}

task* execute() {
*sum= x+y;
return NULL;

class FibTask: public task {
long n;
long* sum;


FibTask(long n_, long* sum_) : n(n_), sum(sum_) {}

task* execute() {
if(n<2) {
*sum = SerialFib(n);
return NULL;
else {
FibContinuation &c = *new(allocate_continuation()) FibContinuation(sum);

// FibTask& a = *new(c.allocate_child()) FibTask(n-2, &c.x);
FibTask& b = *new(c.allocate_child()) FibTask(n-1, &c.y);




return this;

long ParallelFib(long n) {
long sum;
FibTask&a = *new(task::allocate_root()) FibTask(n,&sum);
return sum;

int main()
task_scheduler_init i;
cout << ParallelFib(10) << endl;

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

You're right; this is a documentation bug.

The whole point of recycling is to avoid the need to allocate both tasks. Probaby during a reformatting of the Tutorial a strikethrough was lost. In any case, we'll be sure to fix this.

Thanks for the bug report. I've fixed it in our mainline developement tree. Regrettably, the fix will miss the 2.0 update release.

As Mike indicated, we lostmany of thestrikethough marks text during a major style reformatting. Every time I think we've recovered from that reformatting, someone fines another.

Thanks... good to know I am actually mostly understanding that section. ;-)

Leave a Comment

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