| 201 | |
| 202 | template<typename T> |
| 203 | void ThreadPool<T>::shutdown() { |
| 204 | if (running_.load()) { |
| 205 | std::lock_guard<std::recursive_mutex> lock(manager_mutex_); |
| 206 | running_.store(false); |
| 207 | |
| 208 | drain(); |
| 209 | |
| 210 | task_status_.clear(); |
| 211 | if (manager_thread_.joinable()) { |
| 212 | manager_thread_.join(); |
| 213 | } |
| 214 | |
| 215 | delayed_task_available_.notify_all(); |
| 216 | if (delayed_scheduler_thread_.joinable()) { |
| 217 | delayed_scheduler_thread_.join(); |
| 218 | } |
| 219 | |
| 220 | for (const auto &thread : thread_queue_) { |
| 221 | if (thread->thread_.joinable()) |
| 222 | thread->thread_.join(); |
| 223 | } |
| 224 | |
| 225 | thread_queue_.clear(); |
| 226 | current_workers_ = 0; |
| 227 | while (!delayed_worker_queue_.empty()) { |
| 228 | delayed_worker_queue_.pop(); |
| 229 | } |
| 230 | |
| 231 | worker_queue_.clear(); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | template class utils::ThreadPool<utils::TaskRescheduleInfo>; |
| 236 | template class utils::ThreadPool<int>; |