TBB可能的内存泄漏 [英] TBB possible memory leak
本文介绍了TBB可能的内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
测试程式:
#include< tbb / parallel_invoke.h>
int main(void)
{
tbb :: parallel_invoke([] {},[] {});
return 0;
}
- 使用
g ++ -std = c ++ 11 tmp.cpp -ltbb
-
检查
valgrind --tool = memcheck --track-origins = yes \
--leak-check = full --log-file = report。/ a.out`
-
libtbb
版本:4.0
,valgrind
version:3.8.1
。
上述测试结果的一部分:
可能丢失:6个块中有1,980个字节
问题是:
这是一个 TBB
错误吗?
或者这个可能会丢失
实际上是安全的,它只是一些valgrind不认为安全的代码?
解决方案
最有可能的是,这是一个假阳性,而不是一个错误。至少有几个原因:
- TBB使用自己的内存分配器
libtbbmalloc
它会缓存内存,直到进程终止,并显示为泄漏。 - TBB线程异步运行和终止。可能在
main()
终止后,工作线程仍在运行。 - 删除libtbbmalloc.so.2或tbbmalloc.dll文件,因此使用env.variable运行应用程序
TBB_VERSION = 1
将输出TBB:ALLOCATOR malloc
,但不会TBB:ALLOCATOR scalable_malloc
- 确保所有的TBB主题都已终止
- Compiled using
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
.- TBB uses its own memory allocator
libtbbmalloc
, it caches the memory till the process termination and can appear as a leak. - 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 - remove libtbbmalloc.so.2 or tbbmalloc.dll file so running an application with env.variable
TBB_VERSION=1
will outputTBB: ALLOCATOR malloc
but notTBB: ALLOCATOR scalable_malloc
- make sure all the TBB threads are terminated
为了合理地指控TBB泄漏,排除上述因素,例如: / p>
例如
int main()
{
assert(tbb :: tbb_allocator< int> :: allocator_type()!= tbb :: tbb_allocator< int>可伸缩);
{// TBB范围
tbb :: task_scheduler_init scope;
tbb :: parallel_invoke([] {},[] {});
} // TBB线程在这里开始终止
sleep(10); //等待线程终止
return 0;
}
Test program:
#include <tbb/parallel_invoke.h>
int main(void)
{
tbb::parallel_invoke([]{},[]{});
return 0;
}
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:
In order to reasonably accuse TBB for a leak, exclude the above factors, e.g:
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;
}
这篇关于TBB可能的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文