gpt4 book ai didi

c++ - TBB 我必须破坏 child 的任务还是 parent 照顾?

转载 作者:行者123 更新时间:2023-11-28 05:33:08 25 4
gpt4 key购买 nike

当父级被销毁时,子级是否也会自动销毁,还是我必须明确地销毁它们?

tbb::task *parent = new(tbb::task::allocate_root()) tbb::empty_task;
parent->increment_ref_count();

for (...){
new(parent->allocate_child()) aSampleTask(this);
parent->increment_ref_count();
parent->spawn(*save);
}
parent->wait_for_all();
tbb::task::destroy(*parent);

最佳答案

Usually, a task is automatically destroyed by the scheduler after its method execute returns. But sometimes task objects are used idiomatically (such as for reference counting) without ever running execute. Such tasks should be disposed with method destroy. Explicit task Destruction

您还应该使用static void spawn( task& t ) task Class (见注释)

顺便说一句,你真的需要使用任务吗? TBB提供各种并行algorithms

关于c++ - TBB 我必须破坏 child 的任务还是 parent 照顾?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38964574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com