Optimal strategy to make a C++ hash table, thread safe
Posted
by
Ajeet
on Stack Overflow
See other posts from Stack Overflow
or by Ajeet
Published on 2011-08-16T23:19:27Z
Indexed on
2012/06/02
4:41 UTC
Read the original article
Hit count: 114
(I am interested in design of implementation NOT a readymade construct that will do it all.)
Suppose we have a class HashTable (not hash-map implemented as a tree but hash-table) and say there are eight threads. Suppose read to write ratio is about 100:1 or even better 1000:1. Case A) Only one thread is a writer and others including writer can read from HashTable(they may simply iterate over entire hash table) Case B) All threads are identical and all could read/write.
Can someone suggest best strategy to make the class thread safe with following consideration 1. Top priority to least lock contention 2. Second priority to least number of locks
My understanding so far is thus : One BIG reader-writer lock(semaphore). Specialize the semaphore so that there could be eight instances writer-resource for case B, where each each writer resource locks one row(or range for that matter). (so i guess 1+8 mutexes)
Please let me know if I am thinking on the correct line, and how could we improve on this solution.
© Stack Overflow or respective owner