Theory Assn 2
Theory Assn 2
If we replace the safe Boolean Single-Reader Single-Writer (SRSW) register array (s_table) with
an array of regular Boolean SRSW registers in the "SafeBooleanMRSWRegister," will the
construction yield a regular Boolean MRSW register?
False.
Justification:
Concurrent Reads and Writes: In a regular MRSW register, if a read is concurrent with a write, the read
can return either the value being written or some previous value. However, in the given
"SafeBooleanMRSWRegister" construction, different threads may read different values even when the
write is not concurrent with reads because each thread reads from its own slot in the s_table.
Last Writer Wins: In a regular MRSW register, if a read is not concurrent with any write, it should return
the last value written. The s_table array in "SafeBooleanMRSWRegister" does not guarantee this
because each thread reads from its own slot, and there is no mechanism to ensure that all slots are
updated atomically to reflect the latest write.
Replacing the safe SRSW with regular SRSW registers doesn't address these issues, so the construction
won't yield a regular Boolean MRSW register.
2. You are given the algorithm in Fig. 4.22 for constructing an atomic M-valued SRSW register using
atomic Boolean SRSW registers. Does this proposal work? Either prove the correctness or
present a counterexample.
1. The class uses an array of atomic Boolean SRSW registers (r_bit). Since these are atomic, they provide
the highest level of consistency.
2. The write(int x) operation sets r_bit[x] to true and all previous entries to false. This ensures that any
subsequent read() operation will either see the most recent write or some later write, satisfying the
atomicity criterion.
3. The read() operation scans through the r_bit array to find the first true value and returns its index.
This will be the value of the most recent write() operation, ensuring that read() returns the latest
committed value and satisfies atomicity.
4. The class is designed for a single-reader, single-writer scenario. In this setup, there won't be
concurrent operations, which simplifies the task of maintaining atomicity and consistency.
5. Due to the design of the write () method, it's impossible for the read() method to return a stale or
outdated value, as it will always find the highest index where r_bit is set to true, which corresponds to
the latest write.
So, the AtomicSRSWRegister algorithm appears to work correctly for constructing an atomic M-valued
SRSW register using atomic Boolean SRSW registers. It satisfies the criteria for atomicity and consistency
in a single-reader, single-writer scenario. Therefore, the proposal is correct.