54 lines
1.1 KiB
C
54 lines
1.1 KiB
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <sys/shm.h>
|
|
#include <unistd.h>
|
|
#include "shared.h"
|
|
|
|
void* Consumer(void* arg);
|
|
void consume_item(int item);
|
|
int remove_item(void);
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
if (argc != 2)
|
|
{
|
|
fprintf(stderr, "Usage: %s SharedID# \n", argv[0]);
|
|
exit(1);
|
|
}
|
|
int sharedID = StringToNumber(argv[1]);
|
|
SharedStruct* sharedMem = shmat(sharedID, NULL, 0);
|
|
sem_wait(&sharedMem->semConsumer);
|
|
// TODO: Fix buffer not printing correctly
|
|
printf("%d\n", sharedMem->buffer[0]);
|
|
return 0;
|
|
}
|
|
|
|
// Consumer main function
|
|
// TODO: Add waiting for one consumer at a time
|
|
// Add ability to use shared memory
|
|
void* Consumer(void* arg)
|
|
{
|
|
int consumeNum;
|
|
while (1)
|
|
{
|
|
// down(&full);
|
|
// down(&mutex);
|
|
consumeNum = remove_item();
|
|
// up(&mutex);
|
|
// up(&empty);
|
|
consume_item(consumeNum);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Manage item taken from shared memory
|
|
void consume_item(int item)
|
|
{
|
|
;
|
|
}
|
|
|
|
// Take item out of shared memory
|
|
int remove_item(void)
|
|
{
|
|
;
|
|
} |