Skip to content

Commit 07e02a6

Browse files
authored
Create test.c
1 parent bae8682 commit 07e02a6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

threadpool/test.c

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "threadpool.h"
2+
#include <stdio.h>
3+
#include <unistd.h>
4+
5+
void *f(void *arg)
6+
{
7+
printf("tid is %lu, arg is %d\n", pthread_self(), *(int*)arg);
8+
sleep(1);
9+
return NULL;
10+
}
11+
12+
int main()
13+
{
14+
thread_pool *pool = (thread_pool*)malloc(sizeof(thread_pool));
15+
pool_init(pool, 3);
16+
int* arg = (int*)malloc(sizeof(int)*10);
17+
for(int i=0; i<10; ++i)
18+
{
19+
arg[i]=i;
20+
pool_add_task(pool, f, &arg[i]);
21+
}
22+
sleep(5);
23+
pool_destroy(pool);
24+
free(pool);
25+
}

0 commit comments

Comments
 (0)