ReaderWriterLock.ReleaseReaderLock 메서드

정의

잠금 수를 줄입니다.

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

예외

스레드에 판독기 또는 기록기 잠금이 없습니다.

예제

다음 코드 예제에서는 판독기 잠금을 획득 및 해제하는 방법과 요청 시간이 초과될 때 throw된 예외를 처리하는 방법을 보여 줍니다.

이 코드는 클래스에 제공된 더 큰 예제의 ReaderWriterLock 일부입니다.

// 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
// 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 잠금 수를 줄입니다. 개수가 0에 도달하면 잠금이 해제됩니다.

메모

스레드에 기록기 잠금이 있는 경우 호출은 호출 ReleaseReaderLockReleaseWriterLock과 동일한 효과가 있습니다. 스레드에 잠금이 없으면 호출 ReleaseReaderLock 이 throw됩니다 ApplicationException.

적용 대상

추가 정보

  • 관리되는 스레딩