Hello everyone,
I have been assigned a piece of coursework from to implement a solution for the consumer/producer problem that uses a single producer, a single consumer, and a circular buffer. This should be written in C.
Unfortunately, we have been provided with no learning material and are somehow meant to implement this with no help from the lecturer.
the requirement is as follows:
- Requirement: You are asked to implement a solution for the consumer/producer problem that uses asingle producer, a single consumer, and a circular bounded buffer (i.e. of a fixed size containing, e.g.,integer values). Both the producer and consumer generate/consume an unlimited number of items(e.g. integers). I.e., they can be executed in an infinite loop, assuming that the code runs indefinitely.You are free to choose how to implement this approach, however, it may be recommended to usesemaphores. A successful implementation has:
- A circular buffer of which the size is fixed and configurable (e.g. using a define statement)
- Counters that keeps track of the number of items that have been produced/consumed so far(you ignore wrap-arounds of ints/longs)
- An identification number for every item produced, e.g. its index in the sequence of produceditems
- A simple visualisation that demonstrates how the number of items in the buffer evolves overtime. This can be as simple as printing a number of stars every time an item isproduced/consumed, with each star representing one element currently in the buffer
- Correct synchronisation of any critical sections that may be present, and only where it is strictlynecessary to do so
If anyone can help me out with how to approach this requirement it would be extremely grateful