logo

Crowdly

Browser

Додати до Chrome

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

✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.

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%
Більше питань подібних до цього

Хочете миттєвий доступ до всіх перевірених відповідей на qmplus.qmul.ac.uk?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!

Browser

Додати до Chrome