forked from cindywhan/cosc301_proj04
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test01.c
47 lines (41 loc) · 1.03 KB
/
test01.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
#include <stdio.h>
#include "threadsalive.h"
void thread1(void *arg)
{
int *i = (int *)arg;
printf("t1 arg %d\n", *i);
*i += 7;
fprintf(stderr, "begin t1: %d\n", *i);
ta_yield();
*i += 7;
fprintf(stderr, "end t1: %d\n", *i);
}
void thread2(void *arg)
{
int *i = (int *)arg;
printf("t2 arg %d\n", *i);
*i -= 7;
fprintf(stderr, "begin t2: %d\n", *i);
ta_yield();
*i -= 7;
fprintf(stderr, "end t2: %d\n", *i);
}
int main(int argc, char **argv)
{
printf("Tester for stage 1. Uses all four stage 1 library functions.\n");
ta_libinit();
printf("Made it past init. \n");
int i = 0;
for (i = 0; i < 2; i++) {
ta_create(thread1, (void *)&i);
printf("Created ctx for T1\n");
ta_create(thread2, (void *)&i);
printf("Created ctx for T2\n");
}
printf("Now waiting for threads!\n");
int rv = ta_waitall();
if (rv) {
fprintf(stderr, "%d threads were not ready to run when ta_waitall() was called\n", -rv);
}
return 0;
}