-
Notifications
You must be signed in to change notification settings - Fork 0
/
t5.c
60 lines (44 loc) · 1.03 KB
/
t5.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
/*
* Test Program #5 - Send/Receive
*/
#include <stdio.h>
#include <string.h>
#include "ud_thread.h"
void sender(int thr_id)
{
int i, j;
char *test_message = "Test Message";
printf("Message is: %s, length: %d\n", test_message, strlen(test_message));
for (i = j = 0; i < 3; i++, j++) {
printf("[Pitch] - This is thread %d [%d]...\n", thr_id, j);
send(2, test_message, strlen(test_message));
}
printf("Thread %d is done...\n", thr_id);
t_terminate();
}
void catcher(int thr_id)
{
int i, j;
int snd_id;
int len;
char buffer[1024];
snd_id = 1;
for (i = j = 0; i < 3; i++, j++) {
printf("[Catch] - This is thread %d [%d]...\n", thr_id, j);
receive(&snd_id, buffer, &len);
if(len) {
printf("Catcher got [%s] from thread %d\n", buffer, snd_id);
}
}
printf("Thread %d is done...\n", thr_id);
t_terminate();
}
int main(void) {
int i;
t_init();
t_create(sender, 1, 1);
t_create(catcher, 2, 1);
t_yield();
t_shutdown();
return 0;
}