I am reading a block block. I do not understand this piece of code:
FibTask& a=*new(allocate_child()) FibTask(n-1,&x);
FibTask& b=*new(allocate_child()) FibTask(n-2,&y);
What does this directive mean? class object and new work together? Thanks for the explanation.
The following code is the protection of this FibTask class.
class FibTask: public task
{
public:
const long n;
long* const sum;
FibTask(long n_,long* sum_):n(n_),sum(sum_)
{}
task* execute()
{
if(n<CutOff)
{
*sum=SFib(n);
}
else
{
long x,y;
FibTask& a=*new(allocate_child()) FibTask(n-1,&x);
FibTask& b=*new(allocate_child()) FibTask(n-2,&y);
set_ref_count(3);
spawn(b);
spawn_and_wait_for_all(a);
*sum=x+y;
}
return 0;
}
};
source
share