Multithreaded Hastable Access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a global hashtable instance in my application which is accessed by
threads within that application for readonly access. Do I need to synchronize
the hashtable if readonly access is required? Will the multiple threads be
able to search the hastable simultaneously ?

Thanks

Ajay
 
Ajay said:
I have a global hashtable instance in my application which is accessed by
threads within that application for readonly access. Do I need to synchronize
the hashtable if readonly access is required? Will the multiple threads be
able to search the hastable simultaneously ?

Yes, that's fine. You're okay to have one writer and several readers,
too, so long as none of them try to iterate through the hashtable while
the writer is writing.
 
Personally i would to be safe. You say it is read only but someone has
to fill it in at some point and, as projects seem to go, feature creep
at some point may dictated modifications. I would use a
ReaderWriterLock. This is very nice for items like this. You can have
many readers accessing the data as long as no one is changing it but
feel safe if the collection eventually needs to be changed. At a minimum
I would make sure to wrap the collection up in a manager object that all
accessors use to get at the data. This way you could always add the
ReaderWriterLock later if needed without having to touch all the other
software that needs access to it.

Hope this helps
Leon Lambert
 
Back
Top