473,509 Members | 7,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

static object and by many threads with read-only operation

Hello,

If I have an object that exposes many methods which don't change anything
about the object (at least I'm not aware in terms of implementation of the
..net class). The methods are called by many threads at the same time. What
sort of things that I need to do to make sure the methods and the class are
multi-thread safe? I thought I don't need to do anything but I might be
wrong. For example, I remember reading from some help file that specifically
which multi-thread scenarios are safe for each method (can't find it right
now)

Basically, is this class multi-thread safe if no threads will be modifying
the Hashtable objects, it only loops through etc...

class A
{
static private A s_onlyInstance = new A();
static public A GetInstance() { return s_onlyInstance; }

private A() { }
private Hashtable m_hash1 = ....;
private Hashtable m_hash2 = ....;

public Hashtable Hash1{ get { return m_hash1; } }
public Hashtable Hash2{ get { return m_hash2; } }
}

Thanks!
zeng

Nov 16 '05 #1
1 1371
Please note that I also have ArrayList and objects of other .net classes in
class A as well. thanks for your comments and advice

zeng
"Zeng" <Ze******@hotmail.com> wrote in message
news:uO**************@TK2MSFTNGP11.phx.gbl...
Hello,

If I have an object that exposes many methods which don't change anything
about the object (at least I'm not aware in terms of implementation of the
.net class). The methods are called by many threads at the same time. What sort of things that I need to do to make sure the methods and the class are multi-thread safe? I thought I don't need to do anything but I might be
wrong. For example, I remember reading from some help file that specifically which multi-thread scenarios are safe for each method (can't find it right
now)

Basically, is this class multi-thread safe if no threads will be modifying
the Hashtable objects, it only loops through etc...

class A
{
static private A s_onlyInstance = new A();
static public A GetInstance() { return s_onlyInstance; }

private A() { }
private Hashtable m_hash1 = ....;
private Hashtable m_hash2 = ....;

public Hashtable Hash1{ get { return m_hash1; } }
public Hashtable Hash2{ get { return m_hash2; } }
}

Thanks!
zeng

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2253
by: joe martin | last post by:
Hey all, For singleton code that looks like this: class JoeClass { friend JoeClass &joeFunction(); private: JoeClass() { someFunction();} }
3
3063
by: Amy L. | last post by:
I have a method below called "ResolveHostname" which is called from the ThreadPool.QueueUserWorkItem. My concern is with the static dnsClient class where I am calling dnsClient.Lookup( Hostname)...
18
3303
by: Frank Rizzo | last post by:
Hello, I have a class with all static methods that is called by multiple threads. I was wondering what effect that has on the competing threads. Does Thread2 have to wait until Thread1 is done...
5
1950
by: blah, blah, blah | last post by:
I'm developing a .Net web application and created many helper classes often using static (shared in VB.Net) methods. Do I need to use the lock (SyncLock) statement in these methods to prevent...
1
2212
by: bvisscher | last post by:
I posted this recently in microsoft.public.vc.language and was redirected here. I also searched this ng and found some relavant threads. The most relavent I found was: ...
1
4218
by: philwozza | last post by:
Hi I have a THREAD class that uses the static variable NextThreadID to store the id of the next thread to be created and a static Mutex to protect it. class THREAD { public: int Start(void);...
3
2000
by: clqrq | last post by:
i have just a little question: guess i have a class with a static function and i have different threads running. do i have to expect the problem that 2 treads try to acces CA::static() at the...
7
1985
by: intrader | last post by:
I have the following small classes: //----------------code--------------- using System; using System.Collections.Generic; using System.Text; namespace ValidatorsLibrary { public class...
2
1950
by: Peter K | last post by:
Hi, I am worried about thread-safety in the following code. If two threads call GetObject() is it possible they both create a new AlphaContext object and add it to HttpContext.Items? Can I avoid...
1
3359
by: flowstudioLA | last post by:
I have a template class object that I use as a mesaging queue between threads. I use it as a static object that I initialize like so: foo.h class foo{ static LFQueue<const char*,100lfqMyQueue;...
0
7416
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...
1
7073
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
7506
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
5656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5062
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...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.