logo

Crowdly

Browser

Add to Chrome

A Mailbox class is to be used by multiple threads . The intended behaviour i...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

A Mailbox class is to be used by multiple threads. The intended behaviour is:

- When the mail box is written, it becomes occupied. When the contents are read, the mailbox becomes empty.

- The write method is used to place something in the mailbox. The method should block if the mailbox is already occupied.

- The read method is used to extract something from the mailbox. The method should block if the mailbox is empty.

Consider the code below, which is not thread safe. Select all statements that are true. Incorrect selections reduce your overall marks for this question.

public class Mailbox <T>

{

   private T contents ;

   public Mailbox() {

contents = null ;

}

   public void write(T entry) {

      contents = entry ;

   }

   public T read() {

      T temp = contents;

      contents = null;

      return temp;

   }

}

0%
0%
0%
More questions like this

Want instant access to all verified answers on qmplus.qmul.ac.uk?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome