Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

using task_list with TBB, memory leak?

iupright
Beginner
605 Views

Lets say I have some example code:

task_list myTaskList;
for (itr = parallelOperators.begin(); itr != parallelOperators.end(); itr++ ) {
MYParallelOperator* eachOperator = *itr;
MYParallelTask& newTask = *new( task::allocate_root() ) MYParallelTask( eachOperator );
myTaskList.push_back( newTask );
}
task::spawn_root_and_wait( myTaskList );

My tasks don't spawn any children.. it's all very simple. The above code/patternappears to be working perfectly for me. Is there anything wrong with this approach? The problem I'm having is that it seems like the tasks or resources aren't being destroyed properly.. because it appears that I'm leaking some memory somewhere here. (valgrind tells me so)

First of all, is the above pattern correct?

Thanks, Ian

0 Kudos
3 Replies
ARCH_R_Intel
Employee
605 Views

Yes, the pattern is correct.

The TBB implementation does keep an internal free list of former task objects that it recycles. Those lists are freed after the task scheduler terminates (typicalliy when the last task_scheduler_init object is destroyed). Perhaps Valgrind is not accounting for the free list?

0 Kudos
iupright
Beginner
605 Views

When i call this in a loop over and over, using the same task scheduler,sure it might create some tasks, and then recycle them later.. but in this particular example I have the exact same number of tasks created in each run. Thus, if they are truly getting recycled, it should not continually be growing, and endlessly and leaking memory.

So is this a bug.. or is there something I'm supposed to be doing to clean up the resources?

Ian

0 Kudos
ARCH_R_Intel
Employee
605 Views
You should nothave to do anything special to clean up the resources. Can you send a small self-contained example that exhibits the problem?
0 Kudos
Reply