-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreadtest4.c
More file actions
53 lines (45 loc) · 1.2 KB
/
threadtest4.c
File metadata and controls
53 lines (45 loc) · 1.2 KB
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
#include "types.h"
#include "stat.h"
#include "user.h"
#include "kthread.h"
void* printme() {
printf(1,"Thread %d running !\n", kthread_id());
kthread_exit();
return 0;
}
#define MAX_STACK_SIZE 4096
int
main(int argc, char *argv[])
{
uint *stack, *stack1, *stack2;
int tid, tid1, tid2;
stack = malloc(MAX_STACK_SIZE);
memset(stack, 0, sizeof(*stack));
if ((tid = (kthread_create(printme, stack, MAX_STACK_SIZE))) < 0) {
printf(2, "thread_create error\n");
}
stack1 = malloc(MAX_STACK_SIZE);
memset(stack1, 0, sizeof(*stack1));
if ((tid1 = (kthread_create(printme, stack1, MAX_STACK_SIZE))) < 0) {
printf(2, "thread_create error\n");
}
stack2 = malloc(MAX_STACK_SIZE);
memset(stack2, 0, sizeof(*stack2));
if ((tid2 = (kthread_create(printme, stack2, MAX_STACK_SIZE))) < 0) {
printf(2, "thread_create error\n");
}
printf(1, "Joining %d\n", tid);
if (kthread_join(tid) < 0) {
printf(2, "join error\n");
}
printf(1, "Joining %d\n", tid1);
if (kthread_join(tid1) < 0) {
printf(2, "join error\n");
}
printf(1, "Joining %d\n", tid2);
if (kthread_join(tid2) < 0) {
printf(2, "join error\n");
}
printf(1, "\nAll threads done!\n");
exit();
}