LAB-7牋牋� Producers / Consumers

Problem

Let us consider a system containing a certain number of producers, a certain number of consumers and a buffer. Producers produce elements (integers from 1 to 9) and put them in the buffer while consumers remove elements from the buffer. Obviously, mutual exclusion must be insured, meaning that only one object at a time can access the buffer.

The buffer is a circular buffer with a variable size, initialized when created. We use an array of integers and two indexes, one for the position of the next element to be added and the other for the position of the next element to be removed. Values of the array are initialized to 0, 0 being used to denote the fact that the position is empty.

Producer produces elements between 1 and 9 and put them in the buffer.

Consumer removes elements from the buffer. When an element is removed, its position is set to 0, to illustrate the fact that it is now empty.


Files below present a solution with monitors.

Hosted by www.Geocities.ws

1