ReaderWriterLock.ReleaseWriterLock 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
기록기 잠금의 잠금 수를 줄입니다.
public:
void ReleaseWriterLock();
public void ReleaseWriterLock();
member this.ReleaseWriterLock : unit -> unit
Public Sub ReleaseWriterLock ()
예외
스레드에 기록기 잠금이 없습니다.
예제
다음 코드 예제에서는 기록기 잠금을 획득 및 해제하는 방법과 요청 시간이 초과될 때 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 the writer lock, and handle time-outs.
static void WriteToResource(Random rnd, int timeOut)
{
try {
rwl.AcquireWriterLock(timeOut);
try {
// It's safe for this thread to access from the shared resource.
resource = rnd.Next(500);
Display("writes resource value " + resource);
Interlocked.Increment(ref writes);
}
finally {
// Ensure that the lock is released.
rwl.ReleaseWriterLock();
}
}
catch (ApplicationException) {
// The writer lock request timed out.
Interlocked.Increment(ref writerTimeouts);
}
}
' Request and release the writer lock, and handle time-outs.
Sub WriteToResource(rnd As Random, timeOut As Integer)
Try
rwl.AcquireWriterLock(timeOut)
Try
' It's safe for this thread to read or write from the shared resource.
resource = rnd.Next(500)
Display("writes resource value " & resource)
Interlocked.Increment(writes)
Finally
' Ensure that the lock is released.
rwl.ReleaseWriterLock()
End Try
Catch ex As ApplicationException
' The writer lock request timed out.
Interlocked.Increment(writerTimeouts)
End Try
End Sub
}
End Module
설명
ReleaseWriterLock 는 기록기 잠금 수를 감소합니다. 개수가 0에 도달하면 기록기 잠금이 해제됩니다.
메모
스레드에 판독기 잠금이 있거나 잠금이 없으면 호출 ReleaseWriterLock 이 ApplicationExceptionthrow됩니다.
적용 대상
추가 정보
- 관리되는 스레딩
- ReaderWriterLock