Boost线程泄漏C ++

| 有人可以让我知道Boost线程库是否泄漏。在我看来,它确实可以: Google表示我应该同时使用boost线程和pthread进行编译,并且在1.40版中,此问题已得到解决,但是我仍然会泄漏。请注意,这样做可以编译良好,但可以检测到泄漏。
#include <boost/thread.hpp>  
#include <boost/date_time.hpp>  

void t1(){}

int main(void){
boost::thread th1(t1);
th1.join();
return 1;
}
使用Valgrind,我得到以下输出
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
我还尝试了以下网站上列出的代码:http://antonym.org/2009/05/threading-with-boost---part-i-creating-threads.html 还是一样的问题。     
已邀请:
        这与升压1_46_1有关,因此对于您使用的版本可能不是正确的。如果您真的想说服自己,请查看增强源。 (当我运行您的示例代码时,OSX上的泄漏检测器无法检测到任何泄漏)。 这不是实际的泄漏(除非pthreads,正在使用的boost版本过旧或编译器存在错误)。
get_once_per_thread_epoch
分配一个新的
uintmax_t
,并将其映射到带有a4ѭ的线程本地存储中,
epoch_tss_key
具有关联的析构函数,以释放映射的数据。因此,保证已分配的内存被释放。 我真的不明白valgrind为什么将其检测为泄漏,但这可能是因为pthreads退出函数在valgrind函数之后的某个时刻执行。另一种可能性是pthread函数本身正在泄漏,但是我没有在文档中看到任何暗示这种情况的信息。     

要回复问题请先登录注册