Search code examples
c++multithreadingpocorunnable

C++ POCO run in thread issue


I got one problem when compiling.

I recive error :

In member function 'void CSConnection::onReadable(const Poco::AutoPtr&)':| CSConnection.cpp|92|error: no matching function for call to 'Poco::ThreadPool::start(QuitHandler*)'| CSConnection.cpp|92|note: candidates are:| c:\mingw\bin..\lib\gcc\mingw32\4.7.2........\include\Poco\ThreadPool.h|122|note: void Poco::ThreadPool::start(Poco::Runnable&)| c:\mingw\bin..\lib\gcc\mingw32\4.7.2........\include\Poco\ThreadPool.h|122|note: no known conversion for argument 1 from 'QuitHandler*' to 'Poco::Runnable&'| c:\mingw\bin..\lib\gcc\mingw32\4.7.2........\include\Poco\ThreadPool.h|127|note: void Poco::ThreadPool::start(Poco::Runnable&, const string&)| c:\mingw\bin..\lib\gcc\mingw32\4.7.2........\include\Poco\ThreadPool.h|127|note: candidate expects 2 arguments, 1 provided| ||=== Build finished: 1 errors, 0 warnings (0 minutes, 1 seconds) ===|

Here is quithandler class :

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

Here error line

QuitHandler * qh;
qh = new QuitHandler();
WorkerThreadPool::getInstance().tp->start(qh);

Thanks!


Solution

  • The start method accepts reference, not a pointer: http://pocoproject.org/docs/Poco.ThreadPool.html#11337.

    Quick fix would be:

    QuitHandler qh;
    WorkerThreadPool::getInstance().tp->start(qh);
    

    or

    QuitHandler* qh = new QuitHandler();
    WorkerThreadPool::getInstance().tp->start(*qh);