-
Notifications
You must be signed in to change notification settings - Fork 1
/
queue_test.c
69 lines (51 loc) · 1.06 KB
/
queue_test.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
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <unistd.h>
#include "queue.h"
struct queue q;
void *thread_proc(void *v)
{
sleep(10);
int t, tmp;
for(t=0;t<10;t++)
{
queue_get(&q, &tmp);
printf("ot: got %d\n", tmp);
}
printf("ot: trying to get...\n");
queue_get(&q, &tmp);
printf("ot: got %d\n", tmp);
printf("ot: trying to get...\n");
queue_get(&q, &tmp);
printf("ot: got %d\n", tmp);
return NULL;
}
int main()
{
init_queue(&q, 10, sizeof(int));
pthread_t thread;
pthread_create(&thread, NULL, thread_proc, NULL);
int tmp;
tmp = 0; queue_put(&q, &tmp);
tmp = 1; queue_put(&q, &tmp);
queue_get(&q, &tmp);
printf("got %d\n", tmp);
queue_get(&q, &tmp);
printf("got %d\n", tmp);
tmp = -1; queue_put(&q, &tmp);
tmp = 0; queue_put(&q, &tmp);
queue_get(&q, &tmp);
printf("got %d\n", tmp);
for(tmp=1;tmp<10;tmp++)
{
printf("put %d\n", tmp);
queue_put(&q, &tmp);
}
printf("trying to put 11\n");
tmp = 11;
queue_put(&q, &tmp);
printf("did it\n");
sleep(10);
tmp = 12; queue_put(&q, &tmp);
pthread_join(thread, NULL);
destroy_queue(&q);
}