It seems that even guru software developers seem to misunderstand what constitutes a lock.
A distinction must be made between atomic operations and locks. Atomic operations, such as comparisons and swaps, perform an operation (which would otherwise require two or more instructions) as the only continuous instruction. Locks are built from atomic operations, however, they can lead to revitalization of threads or waiting until the lock is unlocked.
In most cases, if you manage to implement a parallel algorithm with atomic operations without resorting to locking, you will find that it will be an order of magnitude faster. This is why there is so much interest in algorithms without waiting and blocking.
A ton of research has been carried out to introduce various data structures without expectation. Although the code tends to be short, they are notoriously difficult to prove that they really work because of the subtle race conditions that arise. Debugging is also a nightmare. However, a lot of work has been done, and you can find hash cards without waiting / locking, queues (locking Free Lock Free Michael), stacks, lists, trees, the list goes on. If you're lucky, you'll also find some open source versions.
Just unplug my "my-data data structure" and find out what you get.
For further reading on this interesting topic, start with the Art of Multiprocessing Programming by Maurice Herlihy.
Il-bhima
source share