Multi-threaded Application with Readonly Properties
- by Shiftbit
Should my multithreaded application with read only properties require locking? Since nothing is being written I assume there is no need for locks, but I would like to make sure. Would the answer to this question be language agnostic?
Without Lock:
Private m_strFoo as new String = "Foo"
Public ReadOnly Property Foo() As String
Get
return m_strFoo.copy()
End Get
End Property
With Lock:
Private m_strBar as new String = "Bar"
Public ReadOnly Property Bar() As String
Get
SyncLock (me)
return m_strBar.copy()
End Synclock
End Get
End Property