计算机工程与应用 ›› 2012, Vol. 48 ›› Issue (28): 77-83.

• 研发、设计、测试 • 上一篇    下一篇

Linux下通用线程池的改进与实现

唐富强1,于鸿洋1,张  萍2   

  1. 1.电子科技大学 电子科学技术研究院,成都 611731
    2.电子科技大学 电子工程学院,成都 611731
  • 出版日期:2012-10-01 发布日期:2012-09-29

Improvement and implementation of general thread pool under Linux

TANG Fuqiang1, YU Hongyang1, ZHANG Ping2   

  1. 1.Research Institute of Electronic Science and Technology, University of Electronic Science and Technology of China, Chengdu 611731, China
    2.School of Electronic Engineering, University of Electronic Science and Technology of China, Chengdu 611731, China
  • Online:2012-10-01 Published:2012-09-29

摘要: 对线程池的阻塞唤醒机制,动态调整,线程安全退出,参数处理,系统线程数限制等细节进行研究,保证了其在不同应用场景下的独立性和通用性;同时采用一种基于数组的链表机制来改进线程池的查找分配算法,将其时间复杂度稳定在O(1),避免了传统线程池当线程数目过大时导致的查询分配性能下降的问题。实验结果表明,改进后的线程池与传统的系统线程分配方式相比在开销上有很大节省。

关键词: 线程池, 线程退出, 线程查找分配, linux, 阻塞唤醒

Abstract: Do research on blocking and wakeup mechanism, dynamic adjustment, thread exit safely, parameter processing, the system maximam number of threads limits and other details in thread pool, to ensure its?independence and generality?under the?different?scenarios; meanwhile, using a linked list of array-based mechanisms to improve the search and allocation algorithm in thread pool, to be?stable?in?time complexity?O(1), and avoid?the problem that allocate and?query?performance will degrade in the traditional?thread pool when the number of threads?allocated?is too?large, experimental results show that there is a great saving in cost with the traditional distribution system compared to the thread.

Key words: threadpool, thread exit, thread find and assign, linux, blocking and wakeup