If you have a multi-user / single-user queue / FIFO, you can easily make one LockFree using SLIST or the trivial LIFO Lock Free stack. You have a second "private" stack for the user (which can also be done as SLIST for simplicity or any other stack model you choose). The user pops items from the private stack. Whenever a private LIFO is exhasted, you make Flush, not Pop from a shared SLIST (capturing the entire SLIST chain), and then go through the Flushed list by pushing items on a separate stack.
This works for a single producer / single consumer and for multiple manufacturers / single consumer.
However, it does not work for cases with multiple consumers (with one manufacturer or with multiple manufacturers).
In addition, with regard to hash tables, they are an ideal candidate for “splitting”, which simply divides the hash into segments that are locked into cache segments. This is how the parallel Java library works (using 32 bands). If you have an easy read-write lock, the hash table can be obtained at the same time for simultaneous reading, and you will stop only when the write occurs on the contested stripes (and, possibly, if you allow the hash table to be grown).
If you roll on your own, make sure that you alternate locks with hash elements, and do not put all the locks in an array next to each other, so you are less likely to have false access.
Adisak Oct 09 '09 at 16:00 2009-10-09 16:00
source share