-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest3.c
58 lines (44 loc) · 767 Bytes
/
test3.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
#include "types.h"
#include "stat.h"
#include "user.h"
#define NTHREAD 7
void *stack[NTHREAD];
void *retval[NTHREAD];
int tid[NTHREAD];
int mem[NTHREAD];
void *
thread(void *arg)
{
int index = (int)arg;
if(mem[index] != (int)arg) {
printf(1, "WRONG\n");
exit();
}
thread_exit(0);
}
int
main(int argc, char **argv)
{
int i;
printf(1, "TEST3: ");
for(i=0;i<NTHREAD;i++)
stack[i] = malloc(4096);
for(i=0;i<NTHREAD;i++) {
mem[i] = i;
tid[i] = thread_create(thread, (void *)i, stack[i]);
if(tid[i] == -1) {
printf(1, "WRONG\n");
exit();
}
}
for(i=0;i<NTHREAD;i++) {
if(thread_join(tid[i], &retval[i]) == -1) {
printf(1, "WRONG\n");
exit();
}
}
for(i=0;i<NTHREAD;i++)
free(stack[i]);
printf(1, "OK\n");
exit();
}