!46379 [MS][LITE]Fix actor thread pool

Merge pull request !46379 from gongdaguo1/master_fix_actor_thread
This commit is contained in:
i-robot 2022-12-10 09:20:51 +00:00 committed by Gitee
commit bf3d750647
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 21 additions and 1 deletions

View File

@ -36,7 +36,27 @@ class ActorWorker : public Worker {
explicit ActorWorker(ThreadPool *pool, size_t index) : Worker(pool, index) {}
void CreateThread() override;
bool ActorActive();
~ActorWorker() override{};
~ActorWorker() override {
{
std::lock_guard<std::mutex> _l(mutex_);
alive_ = false;
}
cond_var_.notify_one();
bool terminate = false;
int count = 0;
do {
terminate = local_task_queue_->Empty();
if (!terminate) {
auto task_split = local_task_queue_->Dequeue();
(void)TryRunTask(task_split);
}
} while (!terminate && count++ < kMaxCount);
if (thread_.joinable()) {
thread_.join();
}
};
private:
void RunWithSpin();