开发者

Does return inside a lock makes any difference?

开发者 https://www.devze.com 2023-01-08 04:18 出处:网络
Sample One Public _objLock As Object = New Object Public ReadOnly Property MyObjects() As IEnumerable(Of Object)

Sample One

Public _objLock As Object = New Object
Public ReadOnly Property MyObjects() As IEnumerable(Of Object)
   开发者_如何学Python Get
        SyncLock _objLock
            If _myObjects Is Nothing Then
                _myObject = LoadMyObjects()
            End If
            Return _myObjects
        End SyncLock
    End Get
End Property

Sample Two

Public _objLock As Object = New Object
Public ReadOnly Property MyObjects() As IEnumerable(Of Object)
    Get
        SyncLock _objLock
            If _myObjects Is Nothing Then
                _myObject = LoadMyObjects()
            End If              
        End SyncLock
        Return _myObjects
    End Get
End Property

Will there be any difference between these implementations ?


No, returning inside a lock makes no difference. Once you leave the lock, it will cease to exist.

0

精彩评论

暂无评论...
验证码 换一张
取 消