1 public class SafeBooleanMRSWRegister implements Register<Boolean> { 2 boolean[
ID: 663955 • Letter: 1
Question
1 public class SafeBooleanMRSWRegister implements Register<Boolean> {
2 boolean[] s_table; // array of safe SRSW registers
3 public SafeBooleanMRSWRegister(int capacity) {
4 s_table = new boolean[capacity];
5 }
6 public Boolean read() {
7 return s_table[ThreadID.get()];
8 }
9 public void write(Boolean x) {
10 for (int i = 0; i < s_table.length; i++)
11 s_table[i] = x;
12 }
13 }
Consider the safe Boolean MRSW Register construction shown in figure 4.6.True or false: if we replace the safe Boolean MRSW register array with an array of safe M-valued SRSW registers, then the construction yields a safe M-valued MRSW register. Justify your answer.
Explanation / Answer
In the above construction of safe boolean MRSW register, if we replace the safe Boolean MRSW register array with an array of safe M-valued SRSW registers, then the construction will yield a safe M-valued MRSW register, The reason is that if the method calls are not overlapping, each instance of s_table will hold the latest value written onto it. This value is returned when the read() call is executed. If however, there are overlapping method calls, the read() operation can return any of the boolean values since the component registers are safe.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.