此問題與How to get return value from a function called which executes in another thread in TBB?類似,但我正在處理任務。TBB /線程構建模塊:從任務獲取返回值
我有以下代碼:
vector<vector<int> > all;
for(h=0; h<100;h++){
vector<int> vector1= Node(anotherVector[h], value - 1, anotherVector[h].size());
for (unsigned int u = 0; u < vector1.size(); u++) {
all[h].push_back(vector1[u]);
}
}
「向量1」節約從節點遞歸調用的結果。 我想讓TBB調用並行的節點。然後使用「vector1」將其推到「全部」。 我的問題是,如果我嘗試使用任務,我需要從節點返回一個Task對象,以便使用spawn_and_wait_for_all(taskobjectlist here)。
在此先感謝您的幫助。
嗨安東, 感謝您的意見。我進一步瞭解了這一點,但無法找到有效的東西。 例如,當我使用task_groups時,代碼可能如下所示: g-> run(Node(anotherVector [h],value-1,anotherVector [h] .size())); g-> wait(); 我沒有選擇獲取該任務的返回結果。 – Christian
任務可以攜帶對輸出結構的引用。無需返回類似於函數式編程的東西。 – Anton
我在哪裏可以閱讀更多關於此?有什麼地方有例子嗎?謝謝! – Christian