ReaderWriterLock.IsReaderLockHeld 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
현재 스레드에 판독기 잠금이 있는지 여부를 나타내는 값을 가져옵니다.
public:
property bool IsReaderLockHeld { bool get(); };
public bool IsReaderLockHeld { get; }
member this.IsReaderLockHeld : bool
Public ReadOnly Property IsReaderLockHeld As Boolean
속성 값
현재 스레드에 판독기 잠금이 있으면 true
이고, 그렇지 않으면 false
입니다.
예제
다음 코드 예제에서는 교착 상태를 방지하는 데 사용하는 IsReaderLockHeld
방법을 보여 줍니다.
using namespace System;
using namespace System::Threading;
int main()
{
ReaderWriterLock^ rwLock = gcnew ReaderWriterLock;
rwLock->AcquireWriterLock( Timeout::Infinite );
rwLock->AcquireReaderLock( Timeout::Infinite );
if ( rwLock->IsReaderLockHeld )
{
Console::WriteLine( "Reader lock held." );
rwLock->ReleaseReaderLock();
}
else
if ( rwLock->IsWriterLockHeld )
{
Console::WriteLine( "Writer lock held." );
rwLock->ReleaseWriterLock();
}
else
{
Console::WriteLine( "No locks held." );
}
if ( rwLock->IsReaderLockHeld )
{
Console::WriteLine( "Reader lock held." );
rwLock->ReleaseReaderLock();
}
else
if ( rwLock->IsWriterLockHeld )
{
Console::WriteLine( "Writer lock held." );
rwLock->ReleaseWriterLock();
}
else
{
Console::WriteLine( "No locks held." );
}
}
using System;
using System.Threading;
class LockHeld
{
static void Main()
{
ReaderWriterLock rwLock = new ReaderWriterLock();
rwLock.AcquireWriterLock(Timeout.Infinite);
rwLock.AcquireReaderLock(Timeout.Infinite);
if(rwLock.IsReaderLockHeld)
{
Console.WriteLine("Reader lock held.");
rwLock.ReleaseReaderLock();
}
else if(rwLock.IsWriterLockHeld)
{
Console.WriteLine("Writer lock held.");
rwLock.ReleaseWriterLock();
}
else
{
Console.WriteLine("No locks held.");
}
if(rwLock.IsReaderLockHeld)
{
Console.WriteLine("Reader lock held.");
rwLock.ReleaseReaderLock();
}
else if(rwLock.IsWriterLockHeld)
{
Console.WriteLine("Writer lock held.");
rwLock.ReleaseWriterLock();
}
else
{
Console.WriteLine("No locks held.");
}
}
}
Imports System.Threading
Public Class LockHeld
<MTAThread> _
Shared Sub Main()
Dim rwLock As New ReaderWriterLock()
rwLock.AcquireWriterLock(Timeout.Infinite)
rwLock.AcquireReaderLock(Timeout.Infinite)
If rwLock.IsReaderLockHeld Then
Console.WriteLine("Reader lock held.")
rwLock.ReleaseReaderLock()
Else If rwLock.IsWriterLockHeld Then
Console.WriteLine("Writer lock held.")
rwLock.ReleaseWriterLock()
Else
Console.WriteLine("No locks held.")
End If
If rwLock.IsReaderLockHeld Then
Console.WriteLine("Reader lock held.")
rwLock.ReleaseReaderLock()
Else If rwLock.IsWriterLockHeld Then
Console.WriteLine("Writer lock held.")
rwLock.ReleaseWriterLock()
Else
Console.WriteLine("No locks held.")
End If
End Sub
End Class