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