2022-10-13 23:10:33 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/shm.h>
|
|
|
|
#include <unistd.h>
|
2022-10-12 15:44:12 -05:00
|
|
|
#include "shared.h"
|
2022-10-11 19:53:52 -05:00
|
|
|
|
2022-10-13 23:10:33 -05:00
|
|
|
void* Consumer(void* arg);
|
|
|
|
void consume_item(long int item);
|
|
|
|
long int remove_item(void);
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
if (argc != 2)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: %s SharedID# \n", argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
printf("Consumer created.\n");
|
|
|
|
int sharedID = StringToNumber(argv[1]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-12 22:59:06 -05:00
|
|
|
// Consumer main function
|
|
|
|
// TODO: Add waiting for one consumer at a time
|
|
|
|
// Add ability to use shared memory
|
2022-10-12 21:11:15 -05:00
|
|
|
void* Consumer(void* arg)
|
2022-10-11 20:18:38 -05:00
|
|
|
{
|
2022-10-12 21:11:15 -05:00
|
|
|
long int consumeNum;
|
2022-10-11 20:18:38 -05:00
|
|
|
while (1)
|
|
|
|
{
|
2022-10-12 15:44:12 -05:00
|
|
|
// down(&full);
|
|
|
|
// down(&mutex);
|
2022-10-12 21:11:15 -05:00
|
|
|
consumeNum = remove_item();
|
2022-10-12 15:44:12 -05:00
|
|
|
// up(&mutex);
|
|
|
|
// up(&empty);
|
2022-10-12 21:11:15 -05:00
|
|
|
consume_item(consumeNum);
|
2022-10-12 15:44:12 -05:00
|
|
|
break;
|
2022-10-11 20:18:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-12 22:59:06 -05:00
|
|
|
// Manage item taken from shared memory
|
2022-10-12 15:44:12 -05:00
|
|
|
void consume_item(long int item)
|
2022-10-11 20:18:38 -05:00
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2022-10-12 22:59:06 -05:00
|
|
|
// Take item out of shared memory
|
2022-10-11 20:18:38 -05:00
|
|
|
long int remove_item()
|
2022-10-11 19:50:07 -05:00
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|