By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,313 Members | 1,696 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,313 IT Pros & Developers. It's quick & easy.

Multithreaded Hastable Access

P: n/a
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
Jul 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Ajay <Aj**@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

P: n/a
No need to synchronize if the hashtable is readonly. Otherwise you can
use Hashtable.Synchronized() to get a thread safe instance of the hashtable.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

Ajay wrote:
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

Jul 21 '05 #3

P: n/a
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

Ajay wrote:
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

Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.