服务器其他   发布时间:2022-05-15  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Linux C线程池简单实现实例大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

Linux C线程池

三个文件 

1 tpool.h

@H_301_14@
typedef struct tpool_work { 
  void        (*routInE)(void *); 
  void        *arg; 
  struct tpool_work  *next; 
} tpool_work_t; 
 
typedef struct tpool { 
  /* pool characteristics */ 
  int         num_threads; 
  int         max_queue_size; 
  /* pool state */ 
  pthread_t      *tpid; 
  tpool_work_t    *queue; 
  int         front,rear; 
  /* 剩下的任务可以做完,但不能再加新的任务 */ 
  int         queue_closed;   
  /* 剩下的任务都不做了,直接关闭 */ 
  int         shutdown;     
  /* pool synchronization */ 
  pthread_mutex_t   queue_lock; 
  pthread_cond_t   queue_has_task; 
  pthread_cond_t   queue_has_space; 
  pthread_cond_t   queue_empty; 
} *tpool_t; 
 
void tpool_init(tpool_t *tpoolp,int num_threads,int max_queue_sizE); 
 
int tpool_add_work(tpool_t tpool,void(*routInE)(void *),void *arg); 
 
int tpool_destroy(tpool_t tpool,int finish); 

大佬总结

以上是大佬教程为你收集整理的Linux C线程池简单实现实例全部内容,希望文章能够帮你解决Linux C线程池简单实现实例所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: