473,327 Members | 2,069 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,327 software developers and data experts.

Thread safety for a read-only object

I have a main process that will spawn several threads for processing.
Before this happens, the main process creates an instance of a class
that hold configuration data. This configuration data does not change
for the life of the program. Are there any thread synchronization
problem if the data will not be changed?

(PseudoCode)

Sub Main()
'Create a new object that hold config info from an xml file
Dim cfg As New cfgClass()

'Each of these calls spawn a worker thread and pass in a reference
to
'the cfg object.
SpawnThreadA(cfg)
SpawnThreadB(cfg)
SpawnThreadC(cfg)

WaitForThreadsToEnd()
End Sub

Since this object is not CHANGED by the threads, is it safe for them to
read the values? All the properties of the cfgClass are of primitive
types (integer, string, etc) or instances of classes that only have
primitive types. Again, the threads will NEVER CHANGE the values of
these properties, ONLY READ them.

Will I be in trouble if I don't Synchronize access to this object?

Thanks,

Chris

Nov 21 '05 #1
1 1235
Since the config data is only being read, you shouldn't have to worry about
sync issues here. You would need to worry about these issues when (among
other cases) your data is being modified by more than one thread.

hope that helps..
Imran.

I have a main process that will spawn several threads for processing.
Before this happens, the main process creates an instance of a class
that hold configuration data. This configuration data does not change
for the life of the program. Are there any thread synchronization
problem if the data will not be changed?

(PseudoCode)

Sub Main()
'Create a new object that hold config info from an xml file
Dim cfg As New cfgClass()
'Each of these calls spawn a worker thread and pass in a reference
to
'the cfg object.
SpawnThreadA(cfg)
SpawnThreadB(cfg)
SpawnThreadC(cfg)
WaitForThreadsToEnd()
End Sub
Since this object is not CHANGED by the threads, is it safe for them
to read the values? All the properties of the cfgClass are of
primitive types (integer, string, etc) or instances of classes that
only have primitive types. Again, the threads will NEVER CHANGE the
values of these properties, ONLY READ them.

Will I be in trouble if I don't Synchronize access to this object?

Thanks,

Chris


Nov 21 '05 #2

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

Similar topics

3
by: Mike Brown | last post by:
I have questions about thread safety in the 'random' module. When using the random.Random class (be it Mersenne Twister or Wichmann-Hill based), is it sufficiently thread-safe (preserving entropy...
9
by: Alexander Fleck | last post by:
Hi, I' ve to make a software module thread safe. I know how to realize that and what' re the main topics of thread safety. But I don' t know how thread safety can be tested. I read about a test...
14
by: Michi Henning | last post by:
Hi, I can't find a statement about this in the threading sections in the doc... Consider: class Class1 { Class1() { _val = 42;
4
by: The Crow | last post by:
for example i have static readonly SqlParameter and i want to clone them at runtime. as clone operation will not write to SqlParameter object, just reading, should i lock that object during read...
2
by: Robin Haswell | last post by:
Hey guys I've been reading http://www.python.org/peps/pep-0249.html and I don't quite get what level of thread safety I need for my DB connections. If I call db = FOOdb::connect() at the start...
6
by: fniles | last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to clients. As I receive data in 1 thread, I put it into an arraylist, and then I remove the data from arraylist and send it...
1
by: paul.hester | last post by:
Hi all, All of the classes in my DAL are static, with constants defining the stored procedures and parameters. I've been having some problems with my site which makes me wonder if there's a...
0
by: Graham Wideman | last post by:
Folks: Can anyone tell me what controls php's "thread safety" feature? I have an installation where phpinfo() is showing Thread safety: enabled, whereas I need it disabled in order to work...
44
by: climber.cui | last post by:
Hi all, Does anyone have experience on the thread-safty issue with malloc()? Some people said this function provided in stdlib.h is not thread- safe, but someone said it is thread safe. Is it...
13
by: Henri.Chinasque | last post by:
Hi all, I am wondering about thread safety and member variables. If I have such a class: class foo { private float m_floater = 0.0; public void bar(){ m_floater = true; }
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.