EE282 Problem Set Solutions: Spring 2025
EE282 Problem Set Solutions: Spring 2025
Sequential Consistency (SC) maintains strict program order, causing predictability yet potential inefficiency. Total Store Order (TSO) allows store buffering improving performance but needing careful management to avoid unexpected behavior. Release Consistency (RC), being most relaxed, maximizes performance by delaying store visibility but demands explicit synchronization to ensure correct execution order. These differences require developers to carefully select and employ synchronization primitives to maintain correctness .
Introducing FENCE instructions in a program designed under a relaxed consistency model enforces ordering constraints that prevent memory operations from being reordered across the FENCE. This ensures behavior consistent with Sequential Consistency but potentially reduces performance due to increased synchronization overhead, as memory operations must complete in strict order, possibly negating some hardware optimizations .
Under Sequential Consistency (SC), possible outcomes are register1 = 0, register2 = 0; register1 = 1, register2 = 0; register1 = 0, register2 = 1. For Total Store Order (TSO), these outcomes remain the same. However, Release Consistency (RC) additionally allows register1 = 1, register2 = 1 as a possible outcome due to its more relaxed order enforcing .
CAS operation implementation starts by using LR to load the old value at a target address and reserve its modification. A branch checks the loaded value against an expected old value. If it matches, SC attempts storing a new value, which succeeds if no other modifications invalidated the reservation, otherwise, it fails, returning to retry. Here's the assembly: LR to read, BNE for comparison, and SC to store if valid .
Version tags are paired with addresses in synchronization algorithms to detect changes even if the address value appears unchanged. Using LR/SC instructions with version tags, as a change in a version tag indicates an intermediate update, prevents the ABA problem by ensuring that return values accurately reflect sequence changes, not just final states at the time of reading .
The compare-and-swap (CAS) operation can be emulated using load-reserved/store-conditional instructions by first loading a value with LR, then checking it with a branch instruction, followed by SC to attempt storing the new value. This operation checks if another operation has modified the address since it was reserved. While LR/SC can successfully implement CAS, they do not inherently resolve the ABA problem unless the emulation closely monitors additional state like version tags .
Relaxed consistency models such as Release Consistency allow greater flexibility in hardware optimizations like out-of-order execution, store buffering, and caching, which improve performance and energy efficiency in multi-processor systems. However, they challenge software developers with complexity in ensuring correctness through proper synchronization as predictable execution order is not guaranteed unless explicitly enforced with constructs like FENCE instructions .
The ABA problem occurs in synchronized data structures when a location is read twice, sees the same value both times, but the location has been changed in between by another process. Using load-reserved/store-conditional (LR/SC) instructions resolves the ABA problem due to atomicity by reserving the address rather than relying solely on the value, ensuring changes in other threads are not overlooked .
FENCE instructions impose a strict order on the execution of memory operations, ensuring all memory operations before the fence complete before any after the fence start. To enforce sequential consistency on a system with release consistency, FENCE instructions are used between the read and write operations in both threads, maintaining the program order .
Using LR/SC for lock implementation provides atomicity and robustness against concurrent modification by reserving memory locations, eliminating interleaved access issues. This could lead to efficiency gains compared to busy-wait locks since LR/SC reduces unnecessary re-checks by monitoring reservation directly. It ensures robustness by allowing straightforward detection when modifications occur elsewhere, potentially simplifying deadlock avoidance .