Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Project 3-Producer-Consumer Problenm In Section 5.7.1, we presented a semaphore-

ID: 3592692 • Letter: P

Question

Project 3-Producer-Consumer Problenm In Section 5.7.1, we presented a semaphore-based solution to the producer consumer problem using a bounded buffer. In this project, you will design a programming solution to the bounded-buffer problem using the producer and consumer processes shown in Figures 5.9 and 5.10. The solution presented in Section 5.7.1 uses three semaphores: empty and full, which count the number of empty and full slots in the buffer, and mutex, which is a binary (or mutual- exclusion) semaphore that protects the actual insertion or removal of items in the buffer. For this project, you will use standard counting semaphores for empty and full and a mutex lock, rather than a binary semaphore, to represent mutex. The producer and consumer-running as separate threads-will move items to and from a buffer that is synchronized with the empty, full, and mutex structures. You can solve this problem using either Pthreads or the Windows API 8

Explanation / Answer

#Define N 100

int Buffer[N];

c.Sem empty=N;

c.Sem full=0;

B.Sem mutex=1;

Void Producer(void)

{

int itemp,in=0;

while(1)

{

a)itemp=produce_item();

b)DOWN(Empty);

c)DOWN(Mutext);

d)Buffer[in]=itemp;

e)in=(in+1)%N;

f)UP(Mutex);

g)UP(Full);

}

}

Void Consumer(void)

{

int itemc,out=0;

while(1)

{

a)DOWN(full);

b)DOWN(mutex);

c)itemc=Buffer[out];

d)out=(out+1)%100;

e)UP(Mutex);

f)UP(Empty);

g)Produce_item(item c);

}

}