线程池使用中的可达块

时间:2011-07-17 11:55:07

标签: 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::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== 

标题文件:

#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

在主

结束时在启动和关闭时调用Init

0 个答案:

没有答案
相关问题