Multi-threaded Application with Readonly Properties

Posted by Shiftbit on Stack Overflow See other posts from Stack Overflow or by Shiftbit
Published on 2010-06-09T17:26:35Z Indexed on 2010/06/09 17:32 UTC
Read the original article Hit count: 171

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

© Stack Overflow or respective owner

Related posts about multithreading

Related posts about language-agnostic