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

Ratings will be given. Please provide the answers to both parts. Given each of t

ID: 3709724 • Letter: R

Question

Ratings will be given. Please provide the answers to both parts.

Given each of the following variations, say whether it is correct or incorrect. If you say correct explain any of the advantages and disadvantages of the new code. If you say incorrec explain what could go wrong (i.e., trace through an example where it does not behav properly) a) Producer Consumer t wait (mutex); wait (emptyBuffers) put 1 item in bufferi signal (fullBuffers) wait (mutex) wait (fullBuffers); take 1 item from bufferi signal (emptyBuffers); signal (mutex) signal (mutex); b) Producer Consumer wait (fullBuffers); wait (mutex); wait (emptyBuffers); put 1 item in buffer; signal(fullBuffers) wait (mutex); take 1 item from buffer; signal (emptyBuffers); signal (mutex); signal (mutex);

Explanation / Answer

a) It is incorrect

when producer is producing consumer will wait on mutex and hence consumer can't consume, once producer produces, consumer consumes and producer can't get mutex and hence can't produce.

But problem is if producer produces, and then again acquired mutex, then wait emptyBuffers will wait indefinately as consumer can't consume now.

b)

It is correct

Here producer can produce only one item at a time and consumer can consume one item at a time without any race condition or starvation.