ReaderWriterLock.ReleaseReaderLock 메서드

정의

잠금 횟수를 줄입니다.Decrements the lock count.

public:
 void ReleaseReaderLock();
public void ReleaseReaderLock ();
member this.ReleaseReaderLock : unit -> unit
Public Sub ReleaseReaderLock ()

예외

스레드에 판독기 또는 작성기 잠금이 없는 경우The thread does not have any reader or writer locks.

예제

다음 코드 예제에서는 판독기 잠금을 획득 하 고 해제 하는 방법과 요청 시간이 초과 될 때 throw 되는 예외를 처리 하는 방법을 보여 줍니다.The following code example shows how to acquire and release a reader lock, and how to handle the exception thrown when a request times out.

이 코드는 클래스에 대해 제공 된 더 큰 예제의 일부입니다 ReaderWriterLock .This code is part of a larger example provided for the ReaderWriterLock class.

// The complete code is located in the ReaderWriterLock
// class topic.
using namespace System;
using namespace System::Threading;
public ref class Test
{
public:

   // Declaring the ReaderWriterLock at the class level
   // makes it visible to all threads.
   static ReaderWriterLock^ rwl = gcnew ReaderWriterLock;

   // For this example, the shared resource protected by the
   // ReaderWriterLock is just an integer.
   static int resource = 0;

// The complete code is located in the ReaderWriterLock class topic.
using System;
using System.Threading;

public class Example
{
   static ReaderWriterLock rwl = new ReaderWriterLock();
   // Define the shared resource protected by the ReaderWriterLock.
   static int resource = 0;
' The complete code is located in the ReaderWriterLock class topic.
Imports System.Threading

Public Module Example
   Private rwl As New ReaderWriterLock()
   ' Define the shared resource protected by the ReaderWriterLock.
   Private resource As Integer = 0
// Shows how to request and release a reader lock, and
// how to handle time-outs.
static void ReadFromResource( int timeOut )
{
   try
   {
      rwl->AcquireReaderLock( timeOut );
      try
      {

         // It is safe for this thread to read from
         // the shared resource.
         Display( String::Format( "reads resource value {0}", resource ) );
         Interlocked::Increment( reads );
      }
      finally
      {

         // Ensure that the lock is released.
         rwl->ReleaseReaderLock();
      }

   }
   catch ( ApplicationException^ )
   {

      // The reader lock request timed out.
      Interlocked::Increment( readerTimeouts );
   }

}


// Request and release a reader lock, and handle time-outs.
static void ReadFromResource(int timeOut)
{
   try {
      rwl.AcquireReaderLock(timeOut);
      try {
         // It is safe for this thread to read from the shared resource.
         Display("reads resource value " + resource);
         Interlocked.Increment(ref reads);
      }
      finally {
         // Ensure that the lock is released.
         rwl.ReleaseReaderLock();
      }
   }
   catch (ApplicationException) {
      // The reader lock request timed out.
      Interlocked.Increment(ref readerTimeouts);
   }
}
' Request and release a reader lock, and handle time-outs.
Sub ReadFromResource(timeOut As Integer)
   Try
      rwl.AcquireReaderLock(timeOut)
      Try
         ' It's safe for this thread to read from the shared resource.
         Display("reads resource value " & resource)
         Interlocked.Increment(reads)
      Finally
         ' Ensure that the lock is released.
         rwl.ReleaseReaderLock()
      End Try
   Catch ex As ApplicationException
      ' The reader lock request timed out.
      Interlocked.Increment(readerTimeouts)
   End Try
End Sub
};


}
End Module

설명

ReleaseReaderLock 잠금 횟수를 감소 시킵니다.ReleaseReaderLock decrements the lock count. 개수가 0에 도달 하면 잠금이 해제 됩니다.When the count reaches zero, the lock is released.

참고

스레드에 작성기 잠금이 있는 경우 호출은를 호출 하는 ReleaseReaderLock 것과 동일한 효과를 가집니다 ReleaseWriterLock .If a thread has the writer lock, calling ReleaseReaderLock has the same effect as calling ReleaseWriterLock. 스레드에 잠금이 없으면를 호출 하면이 ReleaseReaderLock throw ApplicationException 됩니다.If a thread has no locks, calling ReleaseReaderLock throws an ApplicationException.

적용 대상