C ++ POCO THREAD POOL应用程序崩溃

时间:2013-08-21 10:20:53

标签: c++ multithreading threadpool poco reactor

我的服务器出了问题。

当我想在ThreadPool中执行任务时,服务器崩溃。

以下是使用线程池的函数的一部分:

void CSConnection::onReadable(const AutoPtr<ReadableNotification>& pNf)
{
    try
    {
        int n = _socket.receiveBytes(_pBuffer, BUFFER_SIZE);
        if (n > 0)
        {
         //app.logger().information("Packet s " + nb.format(nBytes) + ", group : " + nb.format(_pBuffer[4]) + ", type : " + nb.format(_pBuffer[6]));
            unsigned short packetID;
            packetID = (_pBuffer[4] * 666) + _pBuffer[6];
            switch(packetID)
            {
                case 666:
                    {
                        QuitHandler* qh = new QuitHandler();
                        qh->_con = this;
                        WorkerThreadPool::getInstance().tp->start(*qh);

执行案例666时,服务器崩溃。 (只有这种情况使用线程池进行测试)

有WorkerThreadPool类:

using Poco::ThreadPool;

class WorkerThreadPool
 {
  private:
        WorkerThreadPool()
        {
            tp = new ThreadPool();
        }
        ~WorkerThreadPool()
        {
            tp->joinAll();
            delete tp;
        }
  public:
        ThreadPool * tp;
        static WorkerThreadPool& getInstance()
        {
          static WorkerThreadPool instance;
          return instance;
        }
 };

有QuitHandler类:

using Poco::Runnable;


    class QuitHandler : public Runnable
    {
        public:
            QuitHandler(){}
            CSConnection * _con;
            void run();
            virtual ~QuitHandler();
        protected:
        private:
            char * _packet;
    };

运行定义:

void QuitHandler::run()
{
    Application &app = Application::instance();
    app.logger().information("quith");
    unsigned short len = 9;
    char * reply = new char[len]();
    ///build packet header
    //set len (it's short)
    reply[0] = len & 0xff;
    reply[1] = (len >> 8) & 0xff;
    reply[4] = 3; //group
    reply[6] = 100; //type
    ///body
    //empty
    _con->sendBlocking(reply, len);
    delete [] reply;
}

日志之前的应用程序崩溃“app.logger()。information(”quith“);”。

感谢。

0 个答案:

没有答案