-
大小: 18KB文件类型: .rar金币: 1下载: 0 次发布日期: 2021-05-29
- 语言: 其他
- 标签: libthreadpoo 线程池 linux
资源简介
一个linux下的c实现的线程池,其中包括线程池的创建、销毁、线程状态等操作。
代码片段和文件信息
#include “thread-pool.h“
static void *tp_work_thread(void *pthread);
static void *tp_manage_thread(void *pthread);
static TPBOOL tp_init(tp_thread_pool *this);
static void tp_close(tp_thread_pool *this);
static void tp_process_job(tp_thread_pool *this tp_work *worker tp_work_desc *job);
static int tp_get_thread_by_id(tp_thread_pool *this int id);
static TPBOOL tp_add_thread(tp_thread_pool *this);
static TPBOOL tp_delete_thread(tp_thread_pool *this);
static int tp_get_tp_status(tp_thread_pool *this);
/**
* user interface. creat thread pool.
* para:
* num: min thread number to be created in the pool
* return:
* thread pool struct instance be created successfully
*/
tp_thread_pool *creat_thread_pool(int min_num int max_num){
tp_thread_pool *this;
this = (tp_thread_pool*)malloc(sizeof(tp_thread_pool));
memset(this 0 sizeof(tp_thread_pool));
//init member function ponter
this->init = tp_init;
this->close = tp_close;
this->process_job = tp_process_job;
this->get_thread_by_id = tp_get_thread_by_id;
this->add_thread = tp_add_thread;
this->delete_thread = tp_delete_thread;
this->get_tp_status = tp_get_tp_status;
//init member var
this->min_th_num = min_num;
this->cur_th_num = this->min_th_num;
this->max_th_num = max_num;
pthread_mutex_init(&this->tp_lock NULL);
//malloc mem for num thread info struct
if(NULL != this->thread_info)
free(this->thread_info);
this->thread_info = (tp_thread_info*)malloc(sizeof(tp_thread_info)*this->max_th_num);
return this;
}
/**
* member function reality. thread pool init function.
* para:
* this: thread pool struct instance ponter
* return:
* true: successful; false: failed
*/
TPBOOL tp_init(tp_thread_pool *this){
int i;
int err;
//creat work thread and init work thread info
for(i=0;imin_th_num;i++){
pthread_cond_init(&this->thread_info[i].thread_cond NULL);
pthread_mutex_init(&this->thread_info[i].thread_lock NULL);
err = pthread_create(&this->thread_info[i].thread_id NULL tp_work_thread this);
if(0 != err){
printf(“tp_init: creat work thread failed\n“);
return FALSE;
}
printf(“tp_init: creat work thread %d\n“ this->thread_info[i].thread_id);
}
//creat manage thread
err = pthread_create(&this->manage_thread_id NULL tp_manage_thread this);
if(0 != err){
printf(“tp_init: creat manage thread failed\n“);
return FALSE;
}
printf(“tp_init: creat manage thread %d\n“ this->manage_thread_id);
return TRUE;
}
/**
* member function reality. thread pool entirely close function.
* para:
* this: thread pool struct instance ponter
* return:
*/
void tp_close(tp_thread_pool *this){
int i;
//close work thread
for(i=0;icur_th_num;i++){
kill(this->thread_info[i].thread_id SIGKILL);
pthread_mutex_destroy(&this->thread_info[i].thread_lock);
pthread_cond_destroy(&this->thread_info[i].thread_cond);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 74 2007-08-17 14:28 libthreadpool\AUTHORS
文件 18009 2007-08-17 14:28 libthreadpool\COPYING
目录 0 2007-08-17 14:28 libthreadpool\example
文件 168 2007-08-17 14:28 libthreadpool\INSTALL
文件 37888 2007-08-17 14:28 libthreadpool\linux线程池的C语言实现.doc
文件 640 2007-08-17 14:28 libthreadpool\Makefile
文件 107 2007-08-17 14:28 libthreadpool\README
文件 9740 2007-08-17 14:28 libthreadpool\src\thread-pool.c
文件 1873 2007-08-17 14:28 libthreadpool\src\thread-pool.h
目录 0 2007-08-17 14:28 libthreadpool\src
目录 0 2007-08-17 14:28 libthreadpool
----------- --------- ---------- ----- ----
68717 12
相关资源
- 嵌入式路由器
- LINUX下完整的人脸识别算法保证可以用
- elasticsearch-6.4.3-全套ela+源码+ik分词器
- 韦东山嵌入式linux应用开发完全手册视
- linux下LaTex配置完全指南
- libpcap-1.9.0
- linux平台 DHT11驱动程序
- ZigBee 协议在Linux上的实现
- 使用Linux的V4L2读取摄像头数据+Opencv图
- 嵌入式Linux系统移植开发-1基于Yocto构
- linux下的QT串口通信
- linux的外文文献
- 老段带你学-鸟哥的Linux私房菜基础+服
- zw_linux0.11带注解源代码.zip
- 基于Linux平台的串口数据接收程序
- ntpdate-4.2.8p12-1.x86_64.rpm
- 东北大学Linux实验报告及代码sk.zip
- understand5.952 for linux破解安装教程
- linux字符设备驱动代码,副实验报告很
- telnet-server-0.17-47.el6.x86_64.rpm和telnet-
- ST7701_854*480显示屏初始化参数
- 最新vivado2019版本,win和linux都有,安
- linux上实现多进程和多线程实现同步互
- linux下使用minicom连接开发板.doc
- ARM linux 和上位机windows10进行TCP/IP网络
- Linux系统下基于Qt的局域网即时通信系
- linux设备驱动详解视频宋宝华百度网盘
- linux 命令解释器
- linux下weblogic安装部署全套
- 全志A13移植Linux所用的配置文件.conf
评论
共有 条评论