On Mar 28, 8:17 am, "Mark S." <m...@yahoo.com wrote:
Every request makes decisions based on what the other request had written to
the static hashTable and then writes what it decided to do back. This
sequential decision makes is required by the code's business logic. If you
or anyone else has a better way to achieve this logic, I'm open to
suggestions.
OK... I'll take a crack at it.
First, though:
1. What are the keys in the hash table? What do they represent?
2. How many keys can there be?
3. How are they structured?
4. How (and when) can new keys be created?
Once I know the answers to these questions, perhaps I can suggest a
better structure.
A preview... what I'm thinking now.
The problem with a hashtable is that the correspondence between a key
and the corresponding hash bucket and its chain of keys is arbitrary.
This means that two threads writing to the same hashtable practically
have to lock the whole structure and therefore run serially.
If, however, you could create a different structure that understands
the structure of your keys, you might be able to selectively lock only
parts of the structure. Viz: one thread writing to the structure under
key A might be able to run in parallel with another thread writing
under key B if the two keys have nothing in common within the data
structure. If you were, for example, to roll your own hash table, you
could attach a different lock object to each hash bucket, and lock the
buckets individually rather than taking out a lock on the entire
table.
Of course, whether this gives you improvements in concurrency entirely
depends upon the nature of your problem. If it is highly likely that
all threads will be working on the same key at the same time then it
doesn't buy you much. If, on the other hand, multiple threads are
likely working on different keys at the same time, and the keys can be
structured so that they are unlikely to land in the same part of the
collection structure, then it's highly likely that threads will run
without any locking contention whatsoever.
As usual, the answer is, "It depends." It depends upon the answers to
those questions, above.