返回是否锁内有什么差别?内有、差别

由网友(碧海蓝天钻戒婚纱我的他)分享简介:Public _objLock As Object = New ObjectPublic ReadOnly Property MyObjects() As IEnumerable(Of Object)GetSyncLock _objLockIf _myObjects Is Nothing Then_myObject...
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
            Return _myObjects
        End SyncLock
    End Get
End Property

的样品有两条

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.

阅读全文

相关推荐

最新文章