Test program:
#include <tbb/parallel_invoke.h>
int main(void)
{
tbb::parallel_invoke([]{},[]{});
return 0;
}
g++ -std=c++11 tmp.cpp -ltbb
Checked 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:
Is this a TBB
bug?
Or is this possible lost
actually safe, it's just some codes that valgrind does not consider safe?
Most likely, it's a false positive, not a bug. There are at least few reasons:
libtbbmalloc
, it caches the memory till the process termination and can appear as a leak.main()
termination, the worker threads are still running. It leads to the same impression for the valgrindIn order to reasonably accuse TBB for a leak, exclude the above factors, e.g:
TBB_VERSION=1
will output TBB: ALLOCATOR malloc
but not TBB: ALLOCATOR scalable_malloc
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With