When I use TImer in ServerApplication (a multithreading app),deadlock occurs.
My Sample code is:
class GateWayServer: public Poco::Util::ServerApplication
{
public:
int main ( const std::vector<std::string>& args )
{
sigset_t newmask;
sigset_t oldmask;
sigemptyset(&newmask);
sigaddset(&newmask, SIGQUIT);
sigaddset(&newmask, SIGTERM);
sigaddset(&newmask, SIGINT);
//just let main thread receive signals
sigprocmask(SIG_BLOCK, &newmask, &oldmask);
//starting bussines threads( NOT RECEIVE SIGNAL )
m_RecvServerSocketPtr = new ServerSocket( 33000 );
TCPServerParams::Ptr tcpParams = new TCPServerParams;
tcpParams->setMaxQueued(1000);
m_recvFactory = new GateWayServerDataConnectionFactory ( );
m_recvTCPServer = new TCPServer ( m_recvFactory , *m_RecvServerSocketPtr ,tcpParams);
m_recvTCPServer->start();
m_fileMergeTimer = new Poco::Timer ( 2*60*1000 , 1*60*1000 );
m_FileMergeCallback = new Poco::TimerCallback<GateWayServer>(*this, &GateWayServer::onFileMergeTimer);
m_fileMergeTimer->start( *m_FileMergeCallback );
//main thread can receive signals
sigprocmask(SIG_SETMASK, &oldmask, NULL);//
//Just call sigwait
waitForTerminationRequest();
stopServerGracefully();
return Application::EXIT_OK;
}
void stopServerGracefully()
{
poco_information( logger(),"program will exit...");
poco_information( logger(),"stoping receive server...");
poco_information( logger(),"stopping RecvTCPServer....");
m_recvTCPServer->stop();
poco_information( logger(),"stopping FileMergeTimer....");
m_fileMergeTimer->stop();
}
void GateWayServer::onFileMergeTimer(Poco::Timer& timer)
{
// doing real work
}
}
Poco::SharedPtr<Poco::Net::ServerSocket> m_RecvServerSocketPtr;
Poco::Net::TCPServerConnectionFactory::Ptr m_recvFactory;
Poco::SharedPtr<Poco::Net::TCPServer> m_recvTCPServer;
Poco::SharedPtr<Poco::Timer> m_fileMergeTimer;
Poco::SharedPtr<Poco::TimerCallback<GateWayServer> > m_FileMergeCallback;
};
int main(int argc, char** argv)
{
GateWayServer app;
return app.run(argc, argv);
}
when the timer m_fileMergeTimer is doing its work, so onFileMergeTimer is called, then I press CTRL+C,
the program will stoped in m_fileMergeTimer->stop();
If the timer is not doing its work,the program behaves normal.
Why?





