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: 3597722 • Letter: B

Question

Below are the pseudocodes for a variation of the solution for the producer-consumer problem. What is the answer from the choice list?

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
}

Question 5 options:

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.

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
}