다음을 통해 공유


ReaderWriterLock.IsReaderLockHeld 속성

정의

현재 스레드에 판독기 잠금이 있는지 여부를 나타내는 값을 가져옵니다.

public:
 property bool IsReaderLockHeld { bool get(); };
public bool IsReaderLockHeld { get; }
member this.IsReaderLockHeld : bool
Public ReadOnly Property IsReaderLockHeld As Boolean

속성 값

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

적용 대상

추가 정보