The main code's store instruction success code will indicate failure.
Broadly speaking across processor architectures, the way these work is processor dependent. I believe that there are a number of implementation strategies would work, however. The processor could take away a reservation on interrupt (implying it would never have to save/restore reservation state on context switch), or, could wait to take away the reservation until another ldaxr
is done, or could wait until another ldaxr
is done at the same cache line or same address. With some approaches, the processor will store the location/address of the reservation, and in other approaches (i.e. maybe single core), it doesn't necessarily have to (unless it wants to verify correct usage of an ld/st pair, which are supposed to match in address and access size).
From this ARM manual, pg B-165 states :
B.6.5 Load-Exclusive and Store-Exclusive instruction constraints:
If two StoreExcl instructions are executed without an intervening LoadExcl instruction the second StoreExcl
instruction returns a status value of 1.
... more details ...
(1 is the failure code and 0 is the success code.)
So, by that text, if the processor executes such a store during interrupt that will cancel any acquired reservation and thus, make the main code's store fail, regardless, perhaps of the memory addresses involved.
While the architectural requirement by the instruction set is usually fairly specific, a wide range of alternative strategies with differing trade-offs can be implemented to accomplish that.