TBB possible memory leak

℡╲_俬逩灬. 提交于 2019-12-23 14:56:50

问题


Test program:

#include <tbb/parallel_invoke.h>

int main(void)
{
    tbb::parallel_invoke([]{},[]{});
    return 0;
}
  1. Compiled using g++ -std=c++11 tmp.cpp -ltbb
  2. Checked with

    valgrind --tool=memcheck --track-origins=yes \
             --leak-check=full --log-file=report ./a.out`
    
  3. 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:

Is this a TBB bug?

Or is this possible lost actually safe, it's just some codes that valgrind does not consider safe?


回答1:


Most likely, it's a false positive, not a bug. There are at least few reasons:

  1. TBB uses its own memory allocator libtbbmalloc, it caches the memory till the process termination and can appear as a leak.
  2. TBB threads run and terminate asynchronously. It is likely that after main() termination, the worker threads are still running. It leads to the same impression for the valgrind

In order to reasonably accuse TBB for a leak, exclude the above factors, e.g:

  1. remove libtbbmalloc.so.2 or tbbmalloc.dll file so running an application with env.variable TBB_VERSION=1 will output TBB: ALLOCATOR malloc but not TBB: ALLOCATOR scalable_malloc
  2. make sure all the TBB threads are terminated

For example

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;
}


来源:https://stackoverflow.com/questions/16598161/tbb-possible-memory-leak

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!