-
Notifications
You must be signed in to change notification settings - Fork 2
/
prodcons1.c
43 lines (34 loc) · 1.02 KB
/
prodcons1.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
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "prodcons.h"
circular_buffer cb;
int main(int argc, char *argv[]) {
if(argc == 6 && atoi(argv[1]) == 1 && atoi(argv[2]) == 1) {
f2 = fopen("prod_in.txt", "w");
f1 = fopen("cons_out.txt", "w");
producerscount=atoi(argv[1]);
endLoop = atoi(argv[1]) * atoi(argv[4]);
PRODUCER_ARGUMENTS producerArgs;
CONSUMER_ARGUMENTS consumerArgs;
producerArgs.prod_id = 1;
producerArgs.seed = atoi(argv[5]);
producerArgs.total = atoi(argv[4]);
consumerArgs.con_id = 1;
cb_init(&cb, atoi(argv[3]), sizeof(int));
pthread_t pro, con;
pthread_mutex_init(&mu, NULL);
pthread_cond_init(¬Ready, NULL);
rc = pthread_create(&con, NULL, consumer, &consumerArgs);
rc = pthread_create(&pro, NULL, producer, &producerArgs);
pthread_join(con, NULL);
pthread_join(pro, NULL);
pthread_mutex_destroy(&mu);
pthread_cond_destroy(¬Ready);
cb_free(&cb);
return 0;
} else {
printf("Wrong argument format!\n");
}
}