![](https://i-blog.csdnimg.cn/blog_migrate/94e084eb327b2084ec4eb850b93d357e.png)
图1:线程池模型
当前线程池中有两个线程正处理任务。
![](https://i-blog.csdnimg.cn/blog_migrate/613a97b8decbe86623c53d4d96da9ca2.png)
图2:线程池运行期间
现在用户新增加任务worker3,首先调用pool_add_worker(),把worker3插入等待队列:如图
![](https://i-blog.csdnimg.cn/blog_migrate/16f223864f932c436ad3751d8283ca5b.png)
图3:用户新增worker3
![](https://i-blog.csdnimg.cn/blog_migrate/5ec32f200fe7bb75ee4d91996eb1431d.png)
图4:调用pool_add_worker,把worker3插入thread_worker中
![](https://i-blog.csdnimg.cn/blog_migrate/fbb09d435f1265c8ba2b68a5ab3e602f.png)
图5:唤醒线程处理任务3
![](https://i-blog.csdnimg.cn/blog_migrate/c89b5f46c4d269530eafeb13cf7edf63.png)
图6线程被唤醒处理任务3
具体实现代码参照[高级篇]
运行效果:
![](https://i-blog.csdnimg.cn/blog_migrate/bce14b95012380e1483e8fed5aa65ae3.png)