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

Below are the pseudocodes for a variation of the solution for the producer-consu

ID: 3597690 • Letter: B

Question

Below are the pseudocodes for a variation of the solution for the producer-consumer problem. Explain what kind problem will happen?

full = new CSemaphore(0);      
empty = new CSemaphore(N);   

Producer process
    while(true) {
         . . .          
          produce a data item
         . . .           
          empty.wait();  
          . . .
     Write a data item to the buffer
          . . .
          full.signal();      
             . . .
}    

Consumer process
while(true) {
      . . .
        full.wait();        
        …
        Remove a data item from buffer
        …
        empty.signal();  
        // consume the data item
}

Produce may write while the consumer is reading.

The code is perfect and no problem will occur.

Producer may suffer from starvation.

Consumer may suffer from starvation.

Deadlock may occur.

Save

Produce may write while the consumer is reading.

The code is perfect and no problem will occur.

Producer may suffer from starvation.

Consumer may suffer from starvation.

Deadlock may occur.

Explanation / Answer

full = new CSemaphore(0);      
empty = new CSemaphore(N);   

Producer process
    while(true) {
         . . .          
          produce a data item
         . . .           
          empty.wait();  
          . . .
     Write a data item to the buffer
          . . .
          full.signal();      
             . . .
}    

Consumer process
while(true) {
      . . .
        full.wait();        
        …
        Remove a data item from buffer
        …
        empty.signal();  
        // consume the data item
}