0

I start a TNonblockingServer from one thread:

void *start_server(void *) {
    server->serve();
    return NULL;
}

pthread_create(&daemon_thread, NULL, start_server, NULL);

, and call server->stop() from the main thread, then try to use pthread_join to wait the background thread exiting gracefully. However the main thread hangs at the pthread_join call.

How could I shut down the thrift server gracefully?

2
  • It is kind of expected that the main thread "hangs" while waiting for the other thread to terminate. Is it doing that properly, as a response the stop command?
    – Bo Persson
    Apr 16, 2011 at 7:41
  • What I expected is that when I call server->stop() from main thread, the server->serve() in background thread would finished, so that this thread can exit. Therefore it would be safe to use pthread_join in main thread to wait this background thread "start_server()" to exit..however "pthread_join()" hangs forever
    – eddyxu
    Apr 16, 2011 at 9:34

2 Answers 2

1

Sorry for the late response

You would just need to stop the underlying libevent

For example, a slightly delayed stop:

tv.tv_usec = 500000;
tv.tv_sec  = 0;
event_base_loopexit(myTNonBlockSvr->getEventBase(), &tv);
0

AFAICT TNonblockingServer::stop() is not implemented. The TNonblockingServer destructor does attempt a clean shutdown though, so you might be able to delete server and have the server shutdown.

This is a complete hack though, and ideally stop() would be properly implemented.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.