Hybrid Parallel Programming Using Locks and STM - Saptarshi Ray, Ryan; Bhaumik, Parama; Kumar Ray, Utpal (International Journal of Computer Sciences and Engineering, 2025)
Software Transactional Memory (STM) is a new alternative approach to locks which solves the problem of synchronization in parallel programs. In STM users have to identify the critical sections in the program and enclose them within transactions by using appropriate STM function calls. Then STM automatically by its internal constructs ensures synchronization in the program. This paper shows how to solve the problem of synchronization in parallel programs by using a hybrid programming approach using both locks and STM. Locks use pessimistic approach to solve the problem of synchronization in parallel programs. STM uses optimistic approach to solve the problem of synchronization in parallel programs. Both the optimistic and pessimistic approaches have some advantages and disadvantages. The disadvantage of optimistic approach is that transactions are aborted when validation cannot be done. This approach works well when there are no conflicts (hence the term optimistic) but wastes work when there are conflicts. Aborting of transactions is a severe problem when the transactions are long and interactive. The disadvantage of pessimistic approach is that large number of locks in the program will lead to very slow execution speed which may cancel out the gains made by solving the problem in parallel. The hybrid approach combines the advantages of the optimistic and pessimistic approaches removing their disadvantages without any degradation of performance.