提高螺纹泄漏C++
Boost thread Leakage C++
有人可以让我知道提升线程库是否泄漏。在我看来,它确实如此:谷歌说我应该同时使用我正在做的 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;
}
使用瓦尔格林德,我得到以下输出
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还是同样的问题。
这与 boost 1_46_1 有关,因此对于您正在使用的版本可能不正确。如果你真的想说服自己,看看提升源。(当我运行您的示例代码时,OSX 上的检漏器不会检测到任何泄漏(。
这不是实际的泄漏(除非 pthreads、您正在使用的过时版本的 boost 或编译器存在错误(。
get_once_per_thread_epoch
mal uintmax_t
loc 使用具有关联析构函数的 epoch_tss_key
将其映射到线程本地存储中,该具有释放映射数据的关联析构函数。因此,保证释放错误定位的内存。
我真的不明白为什么 valgrind 将其检测为泄漏,但这可能是因为 pthreads 退出函数在 valgrind 之后的某个时间点执行。另一种可能性是 pthread 函数本身泄漏,但我在文档中没有看到任何表明情况如此的内容。
相关文章:
- valgrind-hellgrind与泄漏检查的结果不同
- 从构造函数抛出异常时如何克服内存泄漏
- malloc() 可能出现内存泄漏
- 这个极客对极客的trie实现是否存在内存泄漏问题
- 尽管遵循了规则,内存泄漏在哪里
- 为什么调用堆栈数组会导致内存泄漏
- 在简单示例中,Python3 + ctypes 回调会导致内存泄漏
- 使用模板类的自定义列表类型中的内存泄漏
- 为什么以下C++代码中存在内存泄漏?
- Klocwork Inside的资源泄漏
- OpenCV 我应该使用智能指针来防止内存泄漏吗?
- 我是否生成线程并导致内存泄漏?
- 多线程程序中出现意外的内存泄漏
- 为什么此函数会导致内存泄漏?
- 在 C++ 库中使用cythonized python时内存泄漏
- 需要帮助查找内存泄漏
- C++功能泄漏内存,我是C++新手,不确定如何解决
- 瓦尔格林德的内存泄漏使用新的
- CPP 中的瓦尔格林德和记忆泄漏:"Conditional jump or move depends on uninitialised values"
- 无法找出我的代码中的内存泄漏