One embodiment of the present invention provides a
system that avoids locks by transactionally executing critical sections. During operation, the
system receives a program which includes one or more critical sections which are protected by locks. Next, the
system modifies the program so that the critical sections which are protected by locks are executed transactionally without acquiring locks associated with the critical sections. More specifically, the program is modified so that: (1) during transactional execution of a
critical section, the program first determines if a lock associated with the
critical section is held by another process and if so aborts the transactional execution; (2) if the transactional execution of the
critical section completes without encountering an interfering
data access from another process, the program commits changes made during the transactional execution and optionally resumes normal non-transactional execution of the program past the critical section; and (3) if an interfering
data access from another process is encountered during transactional execution of the critical section, the program discards changes made during the transactional execution, and attempts to re-execute the critical section zero or more times.