Philip Machanick
Design of a minimal-contention lock: M-lock, Technical Report CS-PM-2018-08-19: 19 August 2018, 13 pages


As multicore CPUs become more common, scalable synchronization primitives have wider use and ideas previously used in large-scale computation are worth re-opening for wider use. In this paper I explore one approach to scalable sychronization, a minimal-contention lock (M-lock). The key idea is to avoid spinning on a global variable but instead for each blocked task (process or thread) to spin on a local lock representing the task that immediately preceded it in attempting to acquire the lock. This creates an ordering based on the order in which tasks attempt to acquire the lock, preventing starvation. The only globally shared variable is a pointer to the next local lock to be contended for. Each contending task swaps the value of this pointer for a pointer to its own variable. It spins on the variable previously pointed to by the global pointer. Each waiting task spins on a lock only seen by itself and the owner of that lock variable. While a task is spinning, the lock variable can be held in its local cache until invalidated by the lock owner when it releases the lock. Consequently, the amount of bus traffic is considerably less than with a spinlock, which has the pernicious feature that the task releasing the lock is delayed by all the other bus traffic arising from contention for the lock. An MCS lock has similar properties but is more complicated and requires more memory contention-causing operations. This report outlines the design of the M-lock and points to likely performance gains.


(PDF 348KB – also available at ResearchGate, http://dx.doi.org/10.13140/RG.2.2.27891.37928)

@techreport{machanick-mlock-2018,
        Author = {Philip Machanick},
        Institution = {Rhodes University},
        Keywords = {scalable locks, multicore, memory hierarchy},
        Month = {August},
        Number = {CS-PM-2018-08-19},
        Title = {Design of a minimal-contention lock: M-lock},
      	doi = {10.13140/RG.2.2.27891.37928},
        url = {https://homes.cs.ru.ac.za/philip/Publications/Techreports/2018/M-lock-report/M-lock-report.pdf},
        Year = {2018}
}