-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht8.c
More file actions
60 lines (45 loc) · 901 Bytes
/
t8.c
File metadata and controls
60 lines (45 loc) · 901 Bytes
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 #8 - Asynchronous Send/Receive
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ud_thread.h"
void producer(int val)
{
char msg[] = "hello world...";
int i = 0;
for (i = 0; i < 4; i++) {
msg[12] = (char) i+0x30;
send(2, msg, strlen(msg));
printf("thread %d [%s]...\n", val, msg);
}
printf("thread %d terminates...\n", val);
t_terminate();
}
void consumer(int val)
{
int len, who = 0;
char *msg;
msg = (char *) malloc(1024);
do {
who = 0;
receive(&who, msg, &len);
if (who != 0)
printf("I got message [%s] from %d...\n", msg, who);
}
while (who != 0);
free(msg);
t_terminate();
}
int main(void)
{
int i;
t_init();
t_create(producer, 1, 1);
t_create(producer, 3, 1);
t_create(consumer, 2, 1);
t_yield();
t_shutdown();
return 0;
}