Lock-Free Programming
Lock-Free Programming The goal of lock-free programming is not to make synchronization “free”. It is to avoid as much of the extra overhead of traditional locks as possible in highly concurrent scenarios. In a multithreaded environment, the most common and simplest synchronization tool is still a lock. For example, many implementations of std::mutex try to stay in user space when there is no contention. But once contention becomes heavy, threads may block, wake up, and context switch, and performance can drop sharply. Even when the kernel is not involved, locks can still introduce cache synchronization, pipeline stalls, and scheduling overhead. ...