[AGENT++] proper way to shutdown an agent

Jochen Katz katz at agentpp.com
Tue Jun 7 20:37:37 CEST 2011


Hi,

> I am getting a core dump when the agent exits (is shut down), such as in:
> 
> I suspect the problem is that the above get bulk requests is still
> being processed (asynchronously) while the application is exiting and
> destructors are called.

yes, you are right.

> What is the proper way to shut down a multi-threaded agent?

Add the following code after the main loop:

#ifdef AGENTPP_USE_THREAD_POOL
	ThreadPool *threadPool = mib->get_thread_pool();
	if (threadPool)
	{
	  int loops = 0;
	  while (!threadPool->is_idle())
	  {
	    Thread::sleep(500);
	    loops++;
	    if (loops > 10)
	    {
	      LOG_BEGIN(loggerModuleName, INFO_LOG | 1);
	      LOG("Still waiting for active requests to finish");
	      LOG_END;
	      loops = 0;
	    }
	  }
	}
#endif

Regards,
  Jochen



More information about the AGENTPP mailing list