TBB possible memory leak

Testing program:

#include <tbb/parallel_invoke.h> int main(void) { tbb::parallel_invoke([]{},[]{}); return 0; } 
  • Compiled with g++ -std=c++11 tmp.cpp -ltbb
  • Verified with

     valgrind --tool=memcheck --track-origins=yes \ --leak-check=full --log-file=report ./a.out` 
  • libtbb version: 4.0 , valgrind version: 3.8.1 .

Part of the above test result:

 possibly lost: 1,980 bytes in 6 blocks 

Question:

Is this a TBB error?

Or is this possible lost really safe, are these just some codes valgrind does not consider safe?

+4
source share
1 answer

This is most likely a false positive, not a mistake. There are at least a few reasons:

  • TBB uses its own libtbbmalloc memory libtbbmalloc ; it caches memory until the process is complete and may appear as a leak.
  • TBB streams are executed and terminated asynchronously. Probably after the completion of main() worker threads are still working. This gives the same impression of valgrind

To reasonably blame TBB for leakage, eliminate the above factors, for example:

  • delete the libtbbmalloc.so.2 or tbbmalloc.dll file, so running the application using env.variable TBB_VERSION=1 will output TBB: ALLOCATOR malloc , but not TBB: ALLOCATOR scalable_malloc
  • make sure all TBB streams are complete.

for instance

 int main() { assert(tbb::tbb_allocator<int>::allocator_type() != tbb::tbb_allocator<int>::scalable); { // TBB scope tbb::task_scheduler_init scope; tbb::parallel_invoke([]{},[]{}); } // TBB threads start termination here sleep(10); // wait for threads to terminate return 0; } 
+2
source

Source: https://habr.com/ru/post/1481269/


All Articles