Write two seperate programs implementing the producer and the consumer, as well as the (seperate) main function that would evoke them and allow for their appropriate, non-deadlocking working.
Make it possible to run several producers and consumers at the same time.
A buffer of N slots should allow for running of up to N processes, producing and consuming different items.
The number of items produced/consumed at once should not exceed the capacity of the buffer.
The processes should run in loop (indefinitely), with different and variabke speeds. The ordering of items being consumed should reflect production end times.
The consumer should never try to consume from an empty slot. The producer should never try to fill an already filled slot.
Use mutexes and/or semaphores, and/or threads.
An example of the output of desired form:
Producer1 producing item1
Producer3 producing item2
Producer2 producing item3
Consumer1 consuming item1
Consumer2 consuming item2
Producer1 producing item 4
Consumer 3 consuming item 3
(Example files attached - to be run in linux or C compiler)
Running the programs in Linux should be initialised in a manner akin to the following one (files as attached):
gcc start.c -o start -lpthread -lrt
gcc producer.c -o producer -lpthread -lrt
gcc consumer.c -o consumer -lpthread -lrt
gcc unlink.c -o unlink -lpthread -lrt