- Group together parts of the code that must look like atomic, in a way that is transparent, scalable and easy-to-use for the programmer - Differently from monitors, the part of the code to group is not part of the definition of the objects, but is application dependent - Differently from transactions in databases, the code can be any code, not just queries on the DB **Transaction:** an atomic unit of computation (look like instantaneous and without overlap with any other transaction), that can access atomic objects. when executed alone, every transaction successfully terminates. **Program:** set of sequential processes, each alternating transactional and non-transactional code **STM system:** online algorithm that has to ensure the atomic execution of the transactional code of the program. To guarantee efficiency, all transactions can be executed at the same time (optimistic execution approach), but they must be totally ordered - not always possible (where there are different accesses to the same object, with at least one of them that changes it) - commit/abort transactions at their completion point (or even before) - in case of abort, either try to re-execute or notify the invoking proc. - possibility of unbounded delay Conceptually, a transaction is composed of 3 parts: `[READ of atomic reg’s] [local comput.] [WRITE into shared memory]` The key issue is ensuring consistency of the shared memory - as soon as some inconsistencies is discovered, the transaction is aborted Implementation: every transaction uses a local working space - For every shared register: the first READ copies the value of the reg. in the local copy; successive READs will then read from the local copy - Every WRITE modifies the local copy and puts the final value in the shared memory only at the end of the transaction (if it has not been aborted) 4 operations: - `begin_T()`: initializes the local control variables - `X.read_T(), X.write_T()`: described above - `try_to_commit_T()`: decides whether a transaction (non-aborted) can commit #### A Logical Clock based STM system All the READs perform if no inconsistencies arise, or before any inconsistency Let T be a transaction; its read prefix is formed by all its successful READ before its possible abortion. An execution is **opaque** if all committed transactions and all the read prefixes of all aborted transactions appear if executed one after the other, by following their real-time occurrence order. We now present an atomic STM system, called *Transactional Locking 2*: - CLOCK is an atomic READ/FETCH&ADD register initialized at 0 - Every MRMW register X is implemented by a pair of register XX s.t. - XX.val contains the value of X - XX.date contains the date (in terms of CLOCK) of the last update - it is associated with a lock object to guarantee MUTEX when updating the shared memory - For every transaction T, the invoking process maintains - `lc(XX)`: a local copy of the implementation of reg. X - `read_set(T)`: the set of names of all the registers read by T up to that moment - `write_set(T)`: the set of names of all the registers written by T up to that moment - `birthdate(T)`: the value of CLOCK(+1) at the starting of T **Idea:** commit a transaction if and only if (iff) it could appear as executed at its birthdate time **Consistency:** - if T reads X, then it must be that `XX.date < birthdate(T)` - to commit, all registers accessed by T cannot have been modified after T's birthdate (again, `XX.date < birthdate(T)`) ###### Implementation: ``` poi la scrivo giuro ```