开发者

How to stop thrift TNonblockingServer in C++?

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 gracef开发者_JAVA技巧ully. However the main thread hangs at the pthread_join call.

How could I shut down the thrift server gracefully?


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);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜