Code within repository is for Kent State Operating Systems project 1.
This project attempts to implement the producer consumer relationship in the shared memory utilizing a buffer.
The producer generates items and puts items onto the table. The consumer will pick up items.
The table can only hold two items at the same time. When the table is complete, the producer will wait.
When there are no items, the consumer will wait
Semaphores are used to synchronize producer and consumer.
Mutual exclusion is considered.
We use threads in the producer program and consumer program.
Shared memory is used for the “table”.
There are two programs one for the producer and one for the consumer.
To compile the program two steps are nessesary. Clone the respository and run the following:
$ g++ producer.cpp -pthread -o producer
$ g++ consumer.cpp -pthread -o consumer
./producer & ./consumerOutput expectation will appear different each time and the values added to the table are randomly generated numbers of values 1 through 10.
But the following is an example:
Producer produced data: 5
Producer produced data: 6
Consumer is consuming data: 5
Consumer is consuming data: 6