c线程池有完整测试案例二

threadpool.h

#ifndef _THREADPOOL_
#define _THREADPOOL_

#include<stdio.h>
#include<pthread.h>
#include<string.h>
#include<assert.h>
#include<unistd.h>
#include<stdlib.h>
//任务
typedef struct Task
{
   void*(*fun)(void*arg);
   void *arg;
}Task;

//线程池结构
typedef struct ThreadPool
{
   Task *task;
   pthread_t *work_pthread;
   pthread_t *manger_work_pthread;          //线程池管理线程


   pthread_cond_t  isfull;  //任务不满条件变量
   pthread_cond_t  isemety; //任务不为空条件变量

   pthread_mutex_t   mutexpool;  //锁线程池的锁
   pthread_mutex_t   mutexbusy;  
    
   int min;
   int max;
   int busynum;
   int lifenum;
   int exitnum;



   int queue_front; //任务队列存标记
   int queue_rear; //任务队列取标记
   int queue_size; //当前任务数量

   int queue_max; //任务最大数量

   int  showdownfalt; //线程池销毁标志
   
}ThreadPool;

#define PTHREAD_ADDNUM 2    //线程增加数量
#define PTHREAD_DESTORYNUM 2 //线程销毁数量

//线程池创建
int createThreadPool(ThreadPool*pool,int min,int max,int queueMaxNum);

//添加任务
int addTask(ThreadPool*pool,void*(*fun)(void*arg),void*arg);

//销毁线程池
int destroyPthreadPool(ThreadPool*pool);

//工作者回调函数
void* workfun(void*arg); 
//管理者回调函数
void* mangerfun(void*arg);


#endif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值