TBB で PPL のタスクの継続に似たものはありますか? tbb::task
s を手動で割り当て、継続タスクも手動で割り当て、それらの参照カウントを手動で管理する低レベルの TBB メソッドを認識しています。
struct FibContinuation: public task {
long* const sum;
long x, y;
FibContinuation( long* sum_ ) : sum(sum_) {}
task* execute() {
*sum = x+y;
return NULL;
}
};
struct FibTask: public task {
const long n;
long* const sum;
FibTask( long n_, long* sum_ ) :
n(n_), sum(sum_)
{}
task* execute() {
if( n<CutOff ) {
*sum = SerialFib(n);
return NULL;
} else {
// long x, y; This line removed
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);
// Set ref_count to "two children plus one for the wait".
c.set_ref_count(2);
spawn( b );
spawn( a );
// *sum = x+y; This line removed
return NULL;
}
}
};
それは単に恐ろしいことです。生成する子タスクの数を事前に把握し、参照カウントを適切に手動で設定する必要があります。これは非常に壊れやすいコーディングです...
継続を指定する PPL の方法はとても単純です。
create_task([]()->bool
{
// compute something then return a bool result
return true
}).then([](bool aComputedResult)
{
// do something with aComputedResult
});
TBBでそれをどのように達成しますか?