- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadPool.cpp
More file actions
Latest commit
31 lines (23 loc) · 598 Bytes
/
Copy pathThreadPool.cpp
File metadata and controls
31 lines (23 loc) · 598 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//
// Created by Asan on 2023/10/9.
//
#include"ThreadPool.h"
voidThreadPool::init(){
for(int i = 0; i < m_threads.size(); ++i)
{
// 创建工作线程
m_threads.at(i) = std::thread(ThreadWorker(this, i));
}
}
voidThreadPool::shutdown() {
m_shutdown = true;
m_conditional_lock.notify_all(); // 唤醒所有线程
for(int i = 0; i < m_threads.size(); ++i)
{
// 线程是否等待,没有则加入等待队列
if(m_threads.at(i).joinable())
{
m_threads.at(i).join();
}
}
}