CP.free: Lock-free programming
Lock-free programming is writing concurrent code without the use of locks. Because there are no locks, lock-free algorithms tend to be far more subtle and error-prone than their locked counterparts. Many operations that are trivial with locking (e.g. deleting a link from a shared linked list) are much harder without them (following the example, how do you know you’re the only thread inspecting that particular link, so you can free it?)
Because of the added difficulty, expert-level knowledge of many subsystems, including the hardware your program is running on, is generally required in order to write an efficient and correct lock-free algorithm.
Lock-free programming rule summary:
- ???
- ???
Don't use lock-free programming unless you absolutely have to
Reason
It's error-prone and requires expert level knowledge of language features, machine architecture, and data structures.
Alternative: Use lock-free data structures implemented by others as part of some library.