forked from 834810071/NetworkProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
38 lines (33 loc) · 690 Bytes
/
test.cpp
File metadata and controls
38 lines (33 loc) · 690 Bytes
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
//
// Created by jxq on 19-8-15.
//
// p41 线程池
#include "condition.h"
#include "threadpool.h"
#include <iostream>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
void *run (void *arg)
{
printf("threadpool 0x%x working task %d\n", (int)pthread_self(), *(int*)(arg));
sleep(1);
free(arg);
return NULL;
}
int main(void)
{
// 结构体指针需要初始化 不晓得为啥报错
threadpool_t pool;
threadpool_init(&pool, 3);
int i;
for (i = 0; i < 10; ++i)
{
int *a = (int*)malloc(sizeof(int));
*a = i;
threadpool_add_task(&pool, run, a);
}
// sleep(15);
threadpool_destroy(&pool);
return 0;
}