提振螺纹泄漏C ++ [英] Boost thread Leakage C++

查看:106
本文介绍了提振螺纹泄漏C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能有人让我知道是否提升线程库泄漏。在我看来,它的作用:
谷歌表示,我应与提升线程和pthread的,我正在做的,而且在1.40版本的问题已得到解决,但我仍然得到泄漏编译。请注意,这将编译好的,但检测到泄漏。

Could someone let me know whether boost thread library leaks. It seems to me that it does: Google says that I should compile with both boost thread and pthread which I am doing and that in version 1.40 this problem has been fixed but I still get leakage. Note that this will compile fine but leaks are detected.

#include <boost/thread.hpp>  
#include <boost/date_time.hpp>  

void t1(){}

int main(void){
boost::thread th1(t1);
th1.join();
return 1;
}

使用Valgrind的,我得到以下输出

With Valgrind I get the following output

HEAP SUMMARY:
==8209==     in use at exit: 8 bytes in 1 blocks
==8209==   total heap usage: 5 allocs, 4 frees, 388 bytes allocated
==8209== 
==8209== 8 bytes in 1 blocks are still reachable in loss record 1 of 1
==8209==    at 0x4024F20: malloc (vg_replace_malloc.c:236)
==8209==    by 0x4038CCB: boost::detail::get_once_per_thread_epoch() (in /usr/local/lib/libboost_thread.so.1.42.0)
==8209==    by 0x40329D4: ??? (in /usr/local/lib/libboost_thread.so.1.42.0)
==8209==    by 0x4032B26: boost::detail::get_current_thread_data() (in /usr/local/lib/libboost_thread.so.1.42.0)
==8209==    by 0x4033F32: boost::thread::join() (in /usr/local/lib/libboost_thread.so.1.42.0)
==8209==    by 0x804E7C3: main (testboost.cpp)
==8209== 
==8209== LEAK SUMMARY:
==8209==    definitely lost: 0 bytes in 0 blocks
==8209==    indirectly lost: 0 bytes in 0 blocks
==8209==      possibly lost: 0 bytes in 0 blocks
==8209==    still reachable: 8 bytes in 1 blocks
==8209==         suppressed: 0 bytes in 0 blocks

我也试图与在下列网站上列出的code:<一href=\"http://antonym.org/2009/05/threading-with-boost---part-i-creating-threads.html\">http://antonym.org/2009/05/threading-with-boost---part-i-creating-threads.html
还是同样的问题。

I also tried with the code listed at the following website: http://antonym.org/2009/05/threading-with-boost---part-i-creating-threads.html Still the same problem.

推荐答案

这是有关提高1_46_1,所以它可能不是你正在使用的版本如此。看看升压源,如果你真的想说服自己。 (在OSX检漏仪检测不到任何泄漏,当我运行你的榜样code)。

This is in relation to boost 1_46_1, so it may not be true for the version that you are using. Look at the boost sources if you really want to convince yourself. (The leak detector on OSX does not detect any leaks when I run your example code).

这是不是一个实际的泄漏(除非有是不是pthreads的一个bug,提升过时的版本,您正在使用,或你的编译器)。

This is not an actual leak (unless there is a bug with either pthreads, the outdated version of boost that you are using, or your compiler).

get_once_per_thread_epoch mallocs一个新的 uintmax_t型,并将其与 epoch_tss_key 具有关联的析构函数释放映射的数据。因此,malloc内存是保证被释放。

get_once_per_thread_epoch mallocs a new uintmax_t and maps it into thread-local-storage with a epoch_tss_key that has an associated destructor that frees the mapped data. Therefore the malloced memory is guaranteed to be freed.

我真的不明白为什么Valgrind是检测这是一个泄漏,但它可能是因为与pthreads退出功能在Valgrind的那些之后的某一点执行。另一种可能性是,pthread函数本身漏水,但我没有看到文档中任何建议,这是事实。

I really don't understand why valgrind is detecting this as a leak, but it may be because the the pthreads exit functions are executing at some point after the valgrind ones. The other possibility is that the pthread functions themselves are leaking, but I didn't see anything in the documentation that would suggest that this is the case.

这篇关于提振螺纹泄漏C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆