第51讲

来源:互联网 发布:nginx ssl 多证书并存 编辑:程序博客网 时间:2024/06/04 17:51
今日结果: (线程池的应用)
1  创建线程池的结构体:
typedef struct {   
int MinworkNum;    //  最小工作线程数
int  MaxWorkNum;   // 最大工作线程数
int  ReadOffset ;       // 读共享内存偏移量
int WriteOffset;     // 写的共享内存偏移量
int  ChangeWorkNum;   // 改变工作线程数
pthread_mutex_t  WorkMutex ;       // 工作线程互斥锁
}POOL;
2  共享内存的结构体:
typedef struct {
int key ;         // 键值
int  BlockSize;   // 一个数据块的大小
int  BlockNum;    // 有多少个数据块
int  TaskNum;     // 待处理任务数
}SHM;
3  线程池的初始化函数:
void  poolInit( int Max, int Min, POOL *pool){
pool->pt = new  pthread_t [Min];
pool->MinWorkNum = Min;
pool->MaxWorkNum = Max;
pool->RealWorkNum = Min;
pool->ReadOffset = 0;
pool->WriteOffset = 0;
pthread_mutex_init(&(pool->WorkMutex));      
for( int i = 0; i < pool->RealWorkNum; i++){
if(pthread_create(&pool->pt[i], Null, WorkFunc, pool){
perror(" pthread_create");      exit(-1);  
}
}
}
4   还有共享内存要初始化,在共享内存中读取任务,管理线程等。
5  文件中文转码:   iconv -f  GBK  -t UTF-8   <  inputFile   >  outputFile
6  int offset = 2 ;           //  打包要偏移的位数
char buf[1024 +1];      // 存数数据
memcpy( buf + offset, "12345678", 8) ;       //  偏移指针后再存储数据    
明日计划:完成线程池的理解,再结合socket 和以前的ipc,最近学的线程的一些知识完成客户端到服务器的通信,之后了解项目文档。


感想:今天听叶老师说,第三阶段重要的知识点算是已经学完了,剩下的好像不是很难地 知识了。所以自己要做的第一,对以前的不是很理解的知识点再次的回顾弄明白; 第二,学会在现有的知识上进行扩展和强化(这就需要良好的英语阅读能力,自我解决问题的能力)第三,经过这么时间的培训自己也很明白,很重要的知道建立自己独立学习的能力(学会归纳和总结知识,明白自己需要什么)。做自己该做的。
0 0