Thread safety for a read-only object

  • Thread starter Thread starter Chris Dunaway
  • Start date Start date
C

Chris Dunaway

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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top