add destroy thread gracefully

This commit is contained in:
zhjc1124
2023-06-08 07:42:27 +00:00
committed by ob-robot
parent 340151ccc9
commit f4b390d643
25 changed files with 203 additions and 39 deletions

View File

@ -107,6 +107,7 @@ public:
void stop() {
OCCAM_LOG(INFO, "occam thread marked stopped", K(this), K_(id));
ATOMIC_SET(&is_stopped_, true);
share::ObThreadPool::stop();
}
void destroy() {
if (is_inited_) {
@ -269,17 +270,34 @@ public:
}
return ret;
}
void stop()
{
if (is_inited_) {
int ret = OB_SUCCESS;
{
ObThreadCondGuard guard(cv_);
is_stopped_ = true;
}
if (OB_FAIL(cv_.broadcast())) {
OCCAM_LOG(ERROR, "cv broadcast failed", K(ret));
}
for (int64_t idx = 0; idx < thread_num_; ++idx) {
threads_[idx].stop();
}
}
}
void wait()
{
if (is_inited_) {
for (int64_t idx = 0; idx < thread_num_; ++idx) {
threads_[idx].wait();
}
}
}
void destroy()
{
int ret = OB_SUCCESS;
OCCAM_LOG(INFO, "call destroy", K(lbt()));
{
ObThreadCondGuard guard(cv_);
is_stopped_ = true;
}
if (OB_FAIL(cv_.broadcast())) {
OCCAM_LOG(ERROR, "cv broadcast failed", K(ret));
}
stop();
wait();
if (is_inited_) {
for (int64_t idx = 0; idx < thread_num_; ++idx) {
threads_[idx].destroy();