-
Notifications
You must be signed in to change notification settings - Fork 1
/
threadpool_test.c
52 lines (43 loc) · 1.29 KB
/
threadpool_test.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
/**
* threadpool_test.c, copyright 2001 Steve Gribble
*
* Just a regression test for the threadpool code.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <errno.h>
#include "threadpool.h"
extern int errno;
void dispatch_to_me(void *arg) {
int seconds = (int) arg;
fprintf(stdout, " in dispatch %d\n", seconds);
sleep(seconds);
fprintf(stdout, " done dispatch %d\n", seconds);
}
int main(int argc, char **argv) {
fprintf(stdout,"started\n");
threadpool tp;
fprintf(stdout,"initialized threadpool\n");
tp = create_threadpool(2);
fprintf(stdout,"create_threadpool\n");
fprintf(stdout, "**main** dispatch 3\n");
dispatch(tp, dispatch_to_me, (void *) 3);
fprintf(stdout, "**main** dispatch 6\n");
dispatch(tp, dispatch_to_me, (void *) 6);
fprintf(stdout, "**main** dispatch 7\n");
dispatch(tp, dispatch_to_me, (void *) 7);
fprintf(stdout, "**main** done first\n");
sleep(20);
fprintf(stdout, "\n\n");
fprintf(stdout, "**main** dispatch 3\n");
dispatch(tp, dispatch_to_me, (void *) 3);
fprintf(stdout, "**main** dispatch 6\n");
dispatch(tp, dispatch_to_me, (void *) 6);
fprintf(stdout, "**main** dispatch 7\n");
dispatch(tp, dispatch_to_me, (void *) 7);
fprintf(stdout, "**main done second\n");
sleep(20);
exit(-1);
}