-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht6.c
55 lines (42 loc) · 888 Bytes
/
t6.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
/*
* Test Program #6 - Mailbox
*/
#include <stdio.h>
#include <stdlib.h>
#include "ud_thread.h"
mbox *mb;
char *msg[2] = {"hello world...", "bye, bye"};
void producer(int id)
{
int i;
char mymsg[30];
for (i = 0; i < 2; i++) {
sprintf(mymsg, "%s - tid %d", msg[i], id);
printf("Producer (%d): [%s] [length=%d]\n", id, mymsg, strlen(mymsg));
mbox_deposit(mb, mymsg, strlen(mymsg));
}
t_terminate();
}
void consumer(int id)
{
int i;
int len;
char mesg[1024];
for (i = 0; i < 4; i++) {
mbox_withdraw(mb, mesg, &len);
printf("Message from mailbox: [%s]\n", mesg);
}
t_terminate();
}
int main(void) {
t_init();
mbox_create(&mb);
t_create(producer, 1, 1);
t_create(producer, 2, 1);
t_create(consumer, 3, 1);
t_yield();
mbox_destroy(&mb);
t_shutdown();
printf("Done with mailbox test...\n");
return 0;
}