I'm reading the paper An Empirical Evaluation of In-Memory Multi-Version Concurrency Control which is about implementations of MVCC for in-memory databases. Section 3.3 on Two-phase Locking (MV2PL) says:
To perform a read operation on a tuple
A
, the DBMS searches for a visible version by comparing a transaction’sT-id
with the tuples’begin-ts
field. If it finds a valid version, then the DBMS increments that tuple’sread-cnt
field if itstxn-id
field is equal to zero (meaning that no other transaction holds the write lock)
Here is the image in Figure 2c:
The confusion point is about how it actually does this operation atomically: Read location A (txn-id
), if its value is equal to 0 then increment location B (read-cnt
)
Atomic operation in C/C++ does compare-and-swap
only for a single memory location, however, in this case we are dealing with two memory locations. Is there any other CPU intrinsic for this operation, or another trick is employed?