-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestunit_queue.c
More file actions
36 lines (33 loc) · 864 Bytes
/
testunit_queue.c
File metadata and controls
36 lines (33 loc) · 864 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
#include <stdio.h>
#include <pthread.h>
#include "yida_queue.h"
#define N_PRODUCER 1000
#define QUEUE_LEN 1
pthread_t producer_thread[N_PRODUCER];
pthread_t customer_thread;
int numbers[N_PRODUCER];
Queue* queue;
void* my_customer(void* arg){
int* a;
while(1){
a = queue_pop_fast(queue);
printf("This message from producer int address %p, #%d\n",a,*a);
}
}
void* my_producer(void* producer_id){
queue_push(queue,producer_id);
}
int main(){
queue = queue_init(QUEUE_LEN,sizeof(int));
for(int i=0;i<N_PRODUCER;i++){
numbers[i] = i;
}
pthread_create(&customer_thread,NULL,my_customer,NULL);
for(int i=0;i<N_PRODUCER;i++){
pthread_create(producer_thread+i,NULL,my_producer,numbers+i);
}
for(int i=0;i<N_PRODUCER;i++){
pthread_join(producer_thread[i],NULL);
}
// sleep(1);
}