473,385 Members | 1,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Multithreaded Hastable Access

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
3 1417
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Cliff | last post by:
Can someone tell me ...show me how to I would go about creating a Hastable in a HashTable. Say I have items A B C D. I want to be able to call item A the key, and it will give me back B C and D....
3
by: Anthony | last post by:
Hi, How does (Can?) the stream mechanism work in multithreaded programs? I want to implement cout in my multithreaded program.
2
by: pradyumna | last post by:
In Project settins - C/C++ - Code Generation, what is the difference between the option "Multithreaded" and "Multithreaded DLL". I understand that on selecting multithreaded option, single and...
6
by: Dan Kelley | last post by:
We have a multithreaded app that responds to events, and writes these events to a text file. This text file is used by an external system for further processing. We want to be able to write...
1
by: daniel.bron | last post by:
I'm maintaining a C++ application written by a developer who has now left. The app is a multithreaded client/server app for financial data. My compiler is MS visual C++ 6.0. I'm a C++ neophyte....
3
by: Ajay | last post by:
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?...
9
by: nicolas.michel.lava | last post by:
Hi there, I have some trouble using STL containers. I'm working on a multithreaded (pthread) application making heavy usage of STL containers. All accesses to containers are made in locked...
6
by: Stephen Carson | last post by:
I'm trying to build a Web Service that will kick off threads as logging requests come in. These threads will then log to the database. I have been able to make a simple Web Service. I have been...
5
by: RSH | last post by:
I have two HashTables (_CompanyDeductions,_CompanyAccruals) that contain several objects each. I am trying to loop through and print the properties of the objects in the Hashtables: I am trying...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.