TBB之task

這部分介紹Intel TBB task schedulertask scheduler是一個loop模板的引擎,在實際應用中,你應該使用loop模板而不是task scheduler,因爲模板隱藏了調度器的複雜度。然而,如果你有一個算法不能映射到高階模板中的一個,請使用task scheduler

#include "tbb/tbb.h"
#include <cstdio>
using namespace tbb;
class say_hello
{
const char * id;
public:
    say_hello(const char * s) : id(s) { }

    void operator( ) () const{
        printf("hello from task %s\n",id);
    }
};

int main( )
{
task_group tg;
tg.run(say_hello("1")); // spawn 1st task and return
tg.run(say_hello("2")); // spawn 2nd task and return
tg.wait( ); // wait for tasks to complete
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章