Boost 线程池使用中的可访问块

Boost 线程池使用中的可访问块,boost,memory-leaks,threadpool,valgrind,Boost,Memory Leaks,Threadpool,Valgrind,在使用boost threadpool时,我在valgrind中获得以下可达块。还有很多,但写在这里没有任何意义。是否需要这些可到达的块?有没有办法更正这些错误消息 8 bytes in 1 blocks are still reachable in loss record 1 of 20 ==3163== at 0x4C27CC1: operator new(unsigned long) (vg_replace_malloc.c:261) ==3163== by 0x41BA30

在使用boost threadpool时,我在valgrind中获得以下可达块。还有很多,但写在这里没有任何意义。是否需要这些可到达的块?有没有办法更正这些错误消息

 8 bytes in 1 blocks are still reachable in loss record 1 of 20
==3163==    at 0x4C27CC1: operator new(unsigned long) (vg_replace_malloc.c:261)
==3163==    by 0x41BA30: boost::threadpool::detail::pool_core<boost::function0<void>, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks>::pool_core() (pool_core.hpp:144)
==3163==    by 0x41B2AC: boost::threadpool::thread_pool<boost::function0<void>, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks>::thread_pool(unsigned long) (pool.hpp:101)
==3163==    by 0x41A433: infrastructure::logger::InMemoryLoggerThreadPool::InitInMemoryLoggerThreadPool(long) (InMemoryLoggerThreadPool.cpp:20)
==3163==    by 0x412E63: infrastructure::logger::tester_caller_0(int, char**) (main.cpp:89)
==3163==    by 0x413245: main (main.cpp:138)
==3163== 

Init在main的开始和结束时被调用

您必须向我们展示InMemoryLogger线程池的实现(至少是构建和销毁部分)。如果有办法解决这个问题,它就在那里。用代码更新问题。谁调用Init函数?谁调用ShutDown函数?main()分别在开始和结束处调用它们。pool_core(此处:)显示为由智能指针控制,因此可能没有调用ShutDown函数,也可能是有东西引用了pool_core而没有释放。试着制作一个较小的测试用例,只创建一个线程池并销毁它,不需要其他代码,然后看看它是如何工作的。
#ifndef TRUNK_INFRASTRUCTURE_INCLUDE_INMEMORYLOGGER_INMEMORYLOGGERTHREADPOOL_H_
#define TRUNK_INFRASTRUCTURE_INCLUDE_INMEMORYLOGGER_INMEMORYLOGGERTHREADPOOL_H_

#include <assert.h>
#include <stdint.h>

#include "general_utility/include/TechnicalUtilities.h"
#include "third_party/include/boost/threadpool.hpp"

namespace infrastructure {
namespace logger {

class InMemoryLoggerThreadPool {
 public:
 InMemoryLoggerThreadPool() {}
 ~InMemoryLoggerThreadPool() {}
 static void InitInMemoryLoggerThreadPool(int64_t number_of_threads);
 static void ShutDownInMemoryLoggerThreadPool();
 static inline void ScheduleTask(boost::threadpool::pool::task_type task) {
     assert(in_memory_logger_pool__);
     in_memory_logger_pool__->schedule(task);
 }
 static inline void AssertInitialization() {
     assert(in_memory_logger_pool__);
 }
 private:
     static boost::threadpool::pool* in_memory_logger_pool__;
     DISALLOW_COPY_AND_ASSIGN(InMemoryLoggerThreadPool);
 };

 }  // namespace logger
 }  // namespace infrastructure
 #include "infrastructure/include/InMemoryLogger/InMemoryLoggerThreadPool.h"
 namespace infrastructure {
 namespace logger {
 boost::threadpool::pool* InMemoryLoggerThreadPool::
 in_memory_logger_pool__ = NULL;
 void InMemoryLoggerThreadPool::InitInMemoryLoggerThreadPool(int64_t
   number_of_threads) {
   in_memory_logger_pool__ = new boost::threadpool::pool(number_of_threads);
 }
 void InMemoryLoggerThreadPool::ShutDownInMemoryLoggerThreadPool() {
    in_memory_logger_pool__->wait(0);
    delete in_memory_logger_pool__;
 }
 }  // namespace logger
 }  // namespace infrastructure