Visualizing Producer-Consumer problem as a photocopy centre where clients are producers and printers are consumers
Here a circular queue is stored inside the shared memory These programs will be working with shared memory
The repo has three main files
- main.c - creates shared memory
- client.c - inserts data into shared memory
- devices.c - views and deletes data from shared memory
and three additional files which provides support to above main files
- circular_queue.c - has functions to work with Circular Queue
- circular_queue.h - has Circular queue's structure
- photocopy.h - has Photocopy's structure
The Circular queue structure has an array of Photocopy structure. Main program creates a queue for a store and the program will run for the time mentioned as a cmd arg. Client program inserts data into queue. Devices program views the queue and does nothing when the queue is empty, else it simulates printing the data for a specified time and deletes data if time elapsed is 0. All programs will terminate if main program for a store terminates. (i.e) Only a store has a queue, if there is no store then there will be no queue for a closed store.
Execute in this order To create a queue
it will return key for store and queue. use it in next 2 programs.
To view and work with the queue.
To insert data into the queue.
The code has a rare type of bug known as Heisenbug. The program seems to work perfect when debugger is turned on and crashes when it is turned off ( for more details about Heisenbug click here )