#include #include #include #include #include #include "shared.h" void* Producer(void* arg); long int produce_item(void); void insert_item(long int item); int main(int argc, char* argv[]) { if (argc != 2) { fprintf(stderr, "Usage: %s SharedID# \n", argv[0]); exit(1); } srandom((unsigned int) time(NULL)); int sharedID = StringToNumber(argv[1]); SharedStruct* sharedMem = shmat(sharedID, NULL, 0); printf("Adding 5 to shared struct.\n"); sharedMem->buffer[0] = 5; sem_post(&sharedMem->semConsumer); return 0; } // Producer main function // TODO: Add waiting for one producer at a time // Add ability to use shared memory void* Producer(void* arg) { long int insertNum; SharedStruct* sharedMem; while (1) { insertNum = produce_item(); printf("The random number is %li\n", insertNum); // sem_wait(&semProducer); // down(&empty); // down(&mutex); insert_item(insertNum); // sem_post(&semProducer); // up(&mutex); // up(&full); break; } } // Generate a number between 0 and 9 long int produce_item(void) { return random() % 10; } // Insert a number into the shared memory void insert_item(long int item) { ; }