473,405 Members | 2,349 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,405 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 1418
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.