-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction_libary.c
109 lines (97 loc) · 2 KB
/
function_libary.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "function_libary.h"
unsigned int x = 0;
void Function1(void)
{
int i,j;
while (1)
{
i = OS2021_ThreadCreate("random_1","Function2","L",1);
((i>0) ? fprintf(stdout,"Created random_1 successfully\n"):
fprintf(stdout,"Failed to create random_1\n"));
fflush(stdout);
j = OS2021_ThreadCreate("random_2","Function2","L",1);
((j>0) ? fprintf(stdout,"Created random_2 successfully\n"):
fprintf(stdout,"Failed to create random_2\n"));
fflush(stdout);
OS2021_ThreadWaitEvent(3);
((i>0) ? OS2021_ThreadCancel("random_1"): "");
((j>0) ? OS2021_ThreadCancel("random_2"): "");
OS2021_ThreadCancel("f1");
}
}
void Function2(void)
{
int the_num;
int min = 65405;
int max = 65410;
int flag = 0;
while (1)
{
srand((unsigned)time(NULL));
(!flag) ? the_num = rand() % (max - min + 1) + min: (the_num=0) ;
if(the_num == 65409)
{
flag = 1;
fprintf(stdout,"I found 65409.\n");
fflush(stdout);
OS2021_ThreadSetEvent(3);
}
OS2021_TestCancel();
}
}
void Function3(void)
{
int odd = 1;
while(1)
{
fprintf(stdout,"Wait event%d.\n",odd);
fflush(stdout);
OS2021_ThreadWaitEvent(odd);
odd +=2;
if( odd == 9 ){
while (1);
}
}
}
void Function4(void)
{
int odd = 1;
int even = 2;
while(1)
{
OS2021_ThreadWaitTime(500);
fprintf(stdout,"Set even%d.\n",odd);
fflush(stdout);
OS2021_ThreadSetEvent(odd);
odd += 2;
OS2021_ThreadWaitTime(500);
fprintf(stdout,"Set even%d.\n",even);
fflush(stdout);
OS2021_ThreadSetEvent(even);
even += 2;
if( odd == 9 && even == 10){
while (1);
}
}
}
void Function5(void)
{
int even = 2;
while(1)
{
fprintf(stdout,"Wait event%d.\n",even);
fflush(stdout);
OS2021_ThreadWaitEvent(even);
even +=2;
if( even == 10 ){
while (1);
}
}
}
void ResourceReclaim(void)
{
while (1)
{
OS2021_DeallocateThreadResource();
}
}