代码拉取完成,页面将自动刷新
#ifndef _THREAD_POOL_H_
#define _THREAD_POOL_H_
#include <pthread.h>
#ifdef __cplusplus
extern "C"
{
#endif
#define TASK_QUEUE_SIZE 32
#define TASK_NUMBER 2
// task struct
typedef struct _task
{
void (*function)(void *argv);
void *arg;
} task_t;
// thread pool struct
typedef struct _threadpool
{
// task queue
task_t *tasks;
int task_capacity;
int task_size;
int task_head;
int task_tail;
pthread_t manager_id;
pthread_t *worker_ids;
int min_num;
int max_num;
int busy_num;
int live_num;
int exit_num;
pthread_mutex_t mutex_pool;
pthread_mutex_t mutex_busy;
pthread_cond_t not_full;
pthread_cond_t not_empty;
int shutdown;
} threadpool;
// create threadpool
threadpool *threadpool_create(int min, int max);
// destroy threadpool
int threadpool_destroy(threadpool *pool);
// add task into threadpool
void threadpool_add(threadpool *pool, task_t task);
// get busy task num
int threadpool_busy_num(threadpool *pool);
// get live task num
int threadpool_live_num(threadpool *pool);
// manager
void *manager(void *arg);
// workers
void *worker(void *arg);
// one thread exit
void thread_exit(threadpool *pool);
#ifdef __cplusplus
}
#endif // !__cplusplus
#endif // !_THREAD_POOL_H_
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。