Timer in ServerApplication meets deadlock

A general discussion forum.
Posts: 11
Joined: 08 Sep 2009, 07:18

Timer in ServerApplication meets deadlock

Postby zhangwusheng » 18 Jan 2012, 12:33

When I use TImer in ServerApplication (a multithreading app),deadlock occurs.

My Sample code is:

class GateWayServer: public Poco::Util::ServerApplication
int main ( const std::vector<std::string>& args )
sigset_t newmask;
sigset_t oldmask;
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;

m_recvFactory = new GateWayServerDataConnectionFactory ( );
m_recvTCPServer = new TCPServer ( m_recvFactory , *m_RecvServerSocketPtr ,tcpParams);


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

return Application::EXIT_OK;

void stopServerGracefully()
poco_information( logger(),"program will exit...");
poco_information( logger(),"stoping receive server...");

poco_information( logger(),"stopping RecvTCPServer....");

poco_information( logger(),"stopping FileMergeTimer....");

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.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest