如何在 C++ 中停止 thrift TNonblockingServer?
我从一个线程启动一个 TNonblockingServer:
void *start_server(void *) {
server->serve();
return NULL;
}
pthread_create(&daemon_thread, NULL, start_server, NULL);
,并从主线程调用 server->stop()
,然后尝试使用 pthread_join
等待后台线程正常退出。然而,主线程在 pthread_join
调用处挂起。
我怎样才能优雅地关闭 Thrift 服务器?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉回复晚了
您只需要停止底层的 libevent
例如,稍微延迟停止:
Sorry for the late response
You would just need to stop the underlying libevent
For example, a slightly delayed stop:
AFAICT
TNonblockingServer::stop()
未实现。不过,TNonblockingServer
析构函数确实会尝试彻底关闭,因此您可能能够删除服务器并关闭服务器。但这是一个完整的黑客攻击,理想情况下
stop()
能够正确实现。AFAICT
TNonblockingServer::stop()
is not implemented. TheTNonblockingServer
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.