-
Notifications
You must be signed in to change notification settings - Fork 0
/
t11.c
51 lines (34 loc) · 809 Bytes
/
t11.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
t Program #11 - Rendezvous: blocking Send/Receive
*/
#include <stdio.h>
#include <stdlib.h>
#include "ud_thread.h"
void producer(int val) {
char *msg = "hello world...\0";
printf("P: Before block_send()...\n");
block_send(2, msg, strlen(msg));
printf("P: After block_send()...\n");
t_yield();
t_terminate();
}
void consumer(int val) {
int len, who = 1;
char msg[1024];
printf("C: Before block_receive()...\n");
block_receive(&who, msg, &len);
printf("C: After block_receive()...\n");
if (len != 0) {
printf("C %d got message [%s] from P %d...\n", val, msg, who);
}
t_terminate();
}
int main(void) {
t_init();
t_create(producer, 1, 1);
t_create(consumer, 2, 1);
t_yield();
t_yield();
t_yield();
t_shutdown();
return 0;
}