Author: Dmitriy V’jukov for Intel Software Network
While dealing with Transactional Memory I realize new interesting application of Transactional Memory for SINGLE threaded applications. Atomicity guarantees provided by TM can be useful not only for multi-threaded environment, but also for single-threaded environment. Well, it’s actually not astonishing, nevertheless I didn’t hear anything similar in all that hype around TM.
Assume we have complicated operation which involves non-trivial modifications of several objects/containers. Assume that exception can be thrown either by memory allocator, or by copy constructor of some object, or just by application logic. In order to provide strong exception safety in such situation we have to manually write code for cancellation of all those modifications. This can be non-trivial error-prone task.
TM already has all necessary machinery for cancellation of arbitrary operations. TM doesn’t care about complexity of operations, number of involved objects/containers, it can just instantly cancel anything which happens inside atomic block. Why don’t use it?


