ReaderWriterLockSlim.CurrentReadCount 속성

정의

읽기 모드로 잠금을 시작한 고유 스레드의 총 개수를 가져옵니다.

public:
 property int CurrentReadCount { int get(); };
public int CurrentReadCount { get; }
member this.CurrentReadCount : int
Public ReadOnly Property CurrentReadCount As Integer

속성 값

Int32

읽기 모드로 잠금을 시작한 고유 스레드의 총 개수입니다.

예제

다음 예제에서는 읽기 모드의 스레드 수가 임계값을 초과하는 경우 속성을 사용하여 CurrentReadCount 이벤트 로그 항목을 생성하는 방법을 보여 줍니다.

using (ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim()) {
Using rwLock As New ReaderWriterLockSlim()
if (!EventLog.SourceExists("MySource"))
{
    EventLog.CreateEventSource("MySource", "MyPerformanceLog");
}
EventLog performanceLog = new EventLog();
performanceLog.Source = "MySource";
If Not EventLog.SourceExists("MySource") Then
    EventLog.CreateEventSource("MySource", "MyPerformanceLog")
End If
Dim performanceLog As New EventLog()
performanceLog.Source = "MySource"
int readCt = rwLock.CurrentReadCount;
if (readCt > READ_THRESHOLD)
{
    performanceLog.WriteEntry(String.Format(
        "{0} reader threads; exceeds recommended maximum.", readCt));
}
Dim readCt As Integer = rwLock.CurrentReadCount
If readCt > READ_THRESHOLD Then
    performanceLog.WriteEntry(String.Format( _
        "{0} reader threads; exceeds recommended maximum.", readCt))
End If

설명

잠금이 재귀를 허용하고 스레드가 읽기 모드로 여러 번 입력된 경우에도 스레드는 한 번만 계산됩니다.

이 속성은 디버깅, 프로파일링 및 로깅 목적으로만 사용하고 알고리즘의 동작을 제어하지 않습니다. 결과는 계산되는 즉시 변경됩니다. 따라서 이 속성에 따라 결정을 내리는 것은 안전하지 않습니다.

적용 대상