-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.c
75 lines (55 loc) · 1.62 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "src/sl_thread_pool.h"
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
pthread_mutex_t work_mutex;
void *fun1(void * arg)
{
static int count = 0;
// while(1)
{
pthread_mutex_lock(&work_mutex);
count++;
pthread_mutex_unlock(&work_mutex);
printf("I will runing count = %d\n", count);
sleep(1);
}
return NULL;
}
int main(int arg, char **argv)
{
struct sl_thread_pool *creat_pool = NULL;
pthread_mutex_init(&work_mutex, NULL);
int time = -10000;
printf("time: %f\n", (double)time / 10000);
creat_pool = sl_thread_pool_create(5, 10, 1000);
for (int i = 0; i < 20; i++) {
sl_thread_pool_push_task(creat_pool, fun1, NULL);
}
sl_thread_pool_destory(creat_pool);
for (int i = 0; i < 3; i++) {
sl_thread_pool_push_task(creat_pool, fun1, NULL);
}
// sleep(5);
// for (int i = 0; i < 3; i++) {
// sl_thread_pool_push_task(creat_pool, fun1, NULL);
// }
// printf("time: ==============%s============\n", strchr(" \t", ' '));
char* end;
printf("time: ==============%ld============\n", strtol("0x0c006F", &end, 0));
// // for (int i = 0; i < 3; i++) {
// // sl_thread_pool_push_task(creat_pool, fun1, NULL);
// // }
// // sleep(5);
// for (int i = 0; i < 50; i++) {
// sl_thread_pool_push_task(creat_pool, fun1, NULL);
// }
// sleep(50);
// for (int i = 0; i < 3; i++) {
// sl_thread_pool_push_task(creat_pool, fun1, NULL);
// }
// sl_thread_pool_destory(creat_pool);
sleep(10);
return 0;
}