Patent ID: 8839253

Claim:
A method for mutually exclusively executing a critical section by a process in a computer system, wherein a lock acquired by the process permits the process an access to the critical section, the method comprising: in response to an attempt by the process to acquire the lock at an initial time, determining, by a processor of a computer system, that the lock is not currently available for being acquired by the process; in response to said determining that the lock is not currently available for being acquired by the process, performing, by the processor, a loop of N iterations, wherein N is at least 1, and wherein each iteration comprises: calculating a wait time as a difference between a current time and the initial time; determining an average time delay as an average time difference, based on historical data, between a time at which a lock is acquired and a time at which a first attempt to acquire the lock is made; determining an expected time delay as a difference between between the average time delay and the wait time; determining a context switch time; determining whether the expected time delay exceeds the context switch time, and if so then suspending the process from consuming processor cyles and subsequently resuming the process by a supervisor process or a virtual machine monitor, and if not then spinning the process by enabling the process to consume processor cycles; and ascertaining whether an attempt by the process, after said resuming the process or said spinning the process, to acquire the lock was successful, and if so then exiting the loop, and if not then performing a next iteration of the loop, wherein said exiting the loop is performed in iteration N.