[英]How to stop thrift TNonblockingServer in C++?
I start a TNonblockingServer from one thread: 我从一个线程启动TNonblockingServer:
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. ,然后从主线程调用server->stop()
,然后尝试使用pthread_join
等待后台线程正常退出。 However the main thread hangs at the pthread_join
call. 但是,主线程挂在pthread_join
调用处。
How could I shut down the thrift server gracefully? 我如何才能优雅地关闭旧服务器?
Sorry for the late response 回复晚了非常抱歉
You would just need to stop the underlying libevent 您只需要停止基础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 . 未实现 AFAICT TNonblockingServer::stop()
。 The TNonblockingServer
destructor does attempt a clean shutdown though, so you might be able to delete server and have the server shutdown. 但是, TNonblockingServer
析构函数确实尝试进行干净关闭,因此您可以删除服务器并关闭服务器。
This is a complete hack though, and ideally stop()
would be properly implemented. 不过,这是一个完整的技巧,理想情况下, stop()
可以正确实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.