Need Help ?

Home / Expert Answers / Other / The compare&swap primitive is an atomic sequence that compares the content of a given register (call

The compare&swap primitive is an atomic sequence that compares the content of a given register (call ...


The compare&swap primitive is an atomic sequence that compares the content of a given register (call it 'old') with a given memory location. If the contents are not equal, the sequence returns false. If the contents are equal, the sequence swaps the contents of the memory location with the content of another register (call it 'new') and returns true. Pseudocode: function cas(p: pointer to int, old: int, new: int) is: if *p != old, return false; *p <- new; return true. Compare&swap is a universal atomic primitive, powerful enough to implement any other synchronization primitive that performs an atomic read-modify-write sequence on a memory location, and is a building block for mutual exclusion algorithms and for safe concurrent updates to data structures such as queues and lists. The following RISC-V assembly implements a compare&swap, where t0 is the 'old' register, t1 is the 'new' register, and the address of the word in memory that the sequence attempts to swap atomically is in s0. The sequence returns success (1) or failure (0) in register t2. Fill in the gaps in the code. #1: add t2, zero, zero. #2: lr.d t3, (____). #3: bne ____, t3, ____. #4: sc.d ____, (____), ____. #5: exit:. #6: addi ____, ____, zero.



Radioactive Tutors

Radio Active Tutors is a freelance academic writing assistance company. We provide our assistance to the numerous clients looking for a professional writing service.

NEED A CUSTOMIZE PAPER ON THE ABOVE DETAILS?
Order Now


OR

Get outline(Guide) for this assignment at only $10

Get Outline $10

**Outline takes 30 min - 2 hrs depending on the complexity and size of the task
Designed and developed by Brian Mubichi (mubix)
WhatsApp