3 ms·
Perhaps an example will help clarify the difference between mutex locking and CAS (lock-free) operations. Check out Sled[0]. Sled is an implementation of a 'ct
by joshuak 10y ago
Perhaps an example will help clarify the difference between mutex locking and CAS (lock-free) operations. Check out Sled[0]. Sled is an implementation of a 'ctrie'[1] data structure in go. Sled is a lock free key value store. Because it is lock-free any number of threads can read and write to it simultaneously while never interfering with eachother. The application remains parallel at all times.
Locks cause parallel applications to become single threaded for the scope of the lock. This means that most of the time you should just put things that require locks into their own thread and then communicate with that thread from others.
"Do not communicate by sharing memory; instead, share memory by communicating." - ancient go proverb
However, that is still potentially a locking operation because channels must block until both threads are in sync (with some optional caching, to help reduce the effect).
With truly lock free data structures, all threads can share data but do not need to synchronize access. This leads to much, much higher performance.
[0]: https://github.com/Avalanche-io/sled https://github.com/Avalanche-io/sled
[1]: https://github.com/Avalanche-io/sled/blob/master/ctries_paper.pdf https://github.com/Avalanche-io/sled/blob/master/ctries_pape...