-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
76 lines (67 loc) · 1.37 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "threads.h"
#include <stdlib.h>
#include <stdio.h>
void f3(void *arg)
{
int i;
while (1) {
printf("thread 3: %d\n", i++);
thread_yield();
}
}
void f2(void *arg)
{
int i = 0;
while(1) {
printf("thread 2: %d\n",i++);
if (i == 10) {
i = 0;
}
thread_yield();
}
}
void f1(void *arg)
{
int i = 100;
struct thread *t2 = thread_create(f2, NULL);
thread_add_runqueue(t2);
struct thread *t3 = thread_create(f3, NULL);
thread_add_runqueue(t3);
while(1) {
printf("thread 1: %d\n", i++);
if (i == 110) {
i = 100;
}
thread_yield();
}
}
void f4(void *arg)
{
printf("Hello\n");
thread_yield();
printf("World\n");
}
void f5(void *arg)
{
struct thread *t1 = thread_create(f1,NULL);
thread_add_runqueue(t1);
struct thread *t2 = thread_create(f4,NULL);
thread_add_runqueue(t2);
}
int main(int argc, char **argv)
{
/* //test1
struct thread *t1 = thread_create(f1, NULL);
thread_add_runqueue(t1);
thread_start_threading(); */
//test2
struct thread *t1 = thread_create(f1, NULL);
struct thread *t2 = thread_create(f2, NULL);
struct thread *t3 = thread_create(f3, NULL);
thread_add_runqueue(t1);
thread_add_runqueue(t2);
thread_add_runqueue(t3);
thread_start_threading();
printf("\nexited\n");
return 0;
}