-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample_program.c
55 lines (41 loc) · 1.12 KB
/
example_program.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
#include <stdio.h>
#include <unistd.h>
#include <hilolay/hilolay.h>
void recursiva(int cant) {
if(cant > 0) recursiva(cant - 1);
}
void *test1(void *arg) {
int i, tid;
for (i = 0; i < 10; i++) {
tid = hilolay_get_tid();
printf("Soy el ult %d mostrando el numero %d \n", tid, i);
usleep(5000 * i * tid); /* Randomizes the sleep, so it gets larger after a few iterations */
recursiva(i);
// Round Robin will yield the CPU
hilolay_yield();
}
return 0;
}
void *test2(void *arg) {
int i, tid;
for (i = 0; i < 5; i++) {
tid = hilolay_get_tid();
printf("Soy el ult %d mostrando el numero %d \n", tid, i);
usleep(2000 * i * tid); /* Randomizes the sleep, so it gets larger after a few iterations */
recursiva(i);
hilolay_yield();
}
return 0;
}
/* Main program */
int main() {
int i;
hilolay_init();
struct hilolay_t th1;
struct hilolay_t th2;
hilolay_create(&th1, NULL, &test1, NULL);
hilolay_create(&th2, NULL, &test2, NULL);
hilolay_join(&th2);
hilolay_join(&th1);
return hilolay_return(0);
}