1 Star 3 Fork 4

siasjack / libthpool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test.c 1.06 KB
一键复制 编辑 原始数据 按行查看 历史
siasjack 提交于 2019-11-12 22:20 . first commit
//
// test.c
// libthpool
//
// Created by 陈健康 on 2019/11/12.
// Copyright © 2019 陈健康. All rights reserved.
//
#include "libthpool.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
void handle_task_func(void *arg)
{
int s =(*(int*)arg) % 6;
if(s==0)
s=1;
printf("func handle start...arg=%d..sleep=%d..\n",*(int*)arg,s);
sleep(s);
printf("func handle end.......\n");
return ;
}
int main()
{
threadpool_t *ths = NULL;
int data=0,*data_ptr=NULL;
int queue_size,live_thr,busy_thr;
ths = libthpool_init(10, 20, 30);
while(data<100){
data++;
data_ptr = (int*)malloc(sizeof(int));
memset(data_ptr,0,sizeof(int));
*data_ptr = data;
libthpool_task_put(ths, handle_task_func, data_ptr);
//sleep(1);
}
while(1){
libthpool_state(&queue_size, &live_thr, &busy_thr);
if(queue_size == 0 && busy_thr == 0 && live_thr == 10){
break;
}
sleep(1);
}
libthpool_destroy(ths);
return 0;
}
C
1
https://gitee.com/siasjack/libthpool.git
git@gitee.com:siasjack/libthpool.git
siasjack
libthpool
libthpool
master

搜索帮助