LockRecursionException 클래스

정의

잠금에 대한 재귀 정책과 맞지 않는 방식으로 잠금을 재귀적으로 시작할 때 throw되는 예외입니다.

public ref class LockRecursionException : Exception
public class LockRecursionException : Exception
[System.Serializable]
public class LockRecursionException : Exception
type LockRecursionException = class
    inherit Exception
[<System.Serializable>]
type LockRecursionException = class
    inherit Exception
Public Class LockRecursionException
Inherits Exception
상속
LockRecursionException
특성

예제

다음 예제에서는 클래스를 사용할 때의 LockRecursionException 두 가지 원인을 보여 있습니다 ReaderWriterLockSlim . 프로그램에서는 매개 변수가 없는 생성자를 사용하여 재귀를 허용하지 않는 생성자를 만듭니다 ReaderWriterLockSlim . 그러면 프로그램이 읽기 모드에서 잠금으로 들어가는 스레드를 시작합니다. 스레드는 읽기 모드에서 재귀적으로 잠금을 입력하려고 시도하고 결과 예외를 catch합니다. 마지막으로 스레드가 쓰기 모드로 전환하려고 하면 교착 상태가 발생할 가능성이 있습니다. 스레드는 결과 예외를 catch합니다.

using System;
using System.Threading;

class Example
{
    // By default, the lock recursion policy for a new 
    // ReaderWriterLockSlim does not allow recursion.
    static ReaderWriterLockSlim rwls = new ReaderWriterLockSlim();

    static void ThreadProc()
    {
        Console.WriteLine("Acquire the reader lock.");
        rwls.EnterReadLock();

        try
        {
            Console.WriteLine("\nAttempt to acquire the reader lock recursively:");
            rwls.EnterReadLock();
        }
        catch (LockRecursionException lre)
        {
            Console.WriteLine("{0}: {1}", 
                lre.GetType().Name, lre.Message);
        }

        try
        {
            Console.WriteLine("\nAttempt to acquire the writer lock recursively:");
            rwls.EnterWriteLock();
        }
        catch (LockRecursionException lre)
        {
            Console.WriteLine("{0}: {1}", 
                lre.GetType().Name, lre.Message);
        }
    }

    static void Main()
    {
        Thread t = new Thread(ThreadProc);
        t.Start();
        t.Join();
    }
}

/* This code example produces output similar to the following:

Acquire the reader lock.

Attempt to acquire the reader lock recursively:
LockRecursionException: Recursive read lock acquisitions not allowed in this mode.

Attempt to acquire the writer lock recursively:
LockRecursionException: Write lock may not be acquired with read lock held. This pattern is prone to deadlocks. Consider using the upgrade lock.
 */
Imports System.Threading

Class Example
    ' By default, the lock recursion policy for a new 
    ' ReaderWriterLockSlim does not allow recursion.
    Private Shared rwls As New ReaderWriterLockSlim()
    
    Shared Sub ThreadProc() 
        Console.WriteLine("Acquire the reader lock.")
        rwls.EnterReadLock()
        
        Try
            Console.WriteLine(vbCrLf & _
                "Attempt to acquire the reader lock recursively:")
            rwls.EnterReadLock()
        Catch lre As LockRecursionException
            Console.WriteLine("{0}: {1}", _
                lre.GetType().Name, lre.Message)
        End Try
        
        Try
            Console.WriteLine(vbCrLf & _
                "Attempt to acquire the writer lock recursively:")
            rwls.EnterWriteLock()
        Catch lre As LockRecursionException
            Console.WriteLine("{0}: {1}", _
                lre.GetType().Name, lre.Message)
        End Try
    
    End Sub 
    
    Shared Sub Main() 

        Dim t As New Thread(AddressOf ThreadProc)
        t.Start()
        t.Join()
    
    End Sub 
End Class 

' This code example produces output similar to the following:
'
'Acquire the reader lock.
'
'Attempt to acquire the reader lock recursively:
'LockRecursionException: Recursive read lock acquisitions not allowed in this mode.
'
'Attempt to acquire the writer lock recursively:
'LockRecursionException: Write lock may not be acquired with read lock held. This pattern is prone to deadlocks. Consider using the upgrade lock.
'

설명

LockRecursionException 는 다음과 같은 여러 가지 이유로 throw됩니다.

  • 스레드가 재귀적으로 인스턴스 ReaderWriterLockSlim 를 입력하려고 하지만 인스턴스가 재귀를 지원하지 않는 경우

  • 스레드가 처음에 읽기 모드로 잠금에 들어갔을 ReaderWriterLockSlim 때 스레드가 쓰기 모드 또는 업그레이드 가능 모드로 인스턴스를 입력하려고 시도하는 경우. 이는 잠재적인 교착 상태를 나타내므로 허용되지 않습니다.

  • 하나 이상의 재귀 수준을 허용하면 재귀를 추적하는 데 사용되는 내부 스토리지 카운터의 최댓값을 초과합니다. 이 제한은 매우 크므로 일반적으로 애플리케이션에서 초과되지 않아야 합니다.

생성자

LockRecursionException()

오류를 설명하는 시스템 제공 메시지를 사용하여 LockRecursionException 클래스의 새 인스턴스를 초기화합니다.

LockRecursionException(SerializationInfo, StreamingContext)

serialize된 데이터를 사용하여 LockRecursionException 클래스의 새 인스턴스를 초기화합니다.

LockRecursionException(String)

오류를 설명하는 지정한 메시지를 사용하여 LockRecursionException 클래스의 새 인스턴스를 초기화합니다.

LockRecursionException(String, Exception)

지정된 오류 메시지와 해당 예외의 원인인 내부 예외에 대한 참조를 사용하여 LockRecursionException 클래스의 새 인스턴스를 초기화합니다.

속성

Data

예외에 대한 사용자 정의 정보를 추가로 제공하는 키/값 쌍 컬렉션을 가져옵니다.

(다음에서 상속됨 Exception)
HelpLink

이 예외와 연결된 도움말 파일에 대한 링크를 가져오거나 설정합니다.

(다음에서 상속됨 Exception)
HResult

특정 예외에 할당된 코드화된 숫자 값인 HRESULT를 가져오거나 설정합니다.

(다음에서 상속됨 Exception)
InnerException

현재 예외를 발생시킨 Exception 인스턴스를 가져옵니다.

(다음에서 상속됨 Exception)
Message

현재 예외를 설명하는 메시지를 가져옵니다.

(다음에서 상속됨 Exception)
Source

오류를 발생시키는 애플리케이션 또는 개체의 이름을 가져오거나 설정합니다.

(다음에서 상속됨 Exception)
StackTrace

호출 스택의 직접 실행 프레임 문자열 표현을 가져옵니다.

(다음에서 상속됨 Exception)
TargetSite

현재 예외를 throw하는 메서드를 가져옵니다.

(다음에서 상속됨 Exception)

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetBaseException()

파생 클래스에서 재정의된 경우 하나 이상의 후속 예외의 근본 원인이 되는 Exception 을 반환합니다.

(다음에서 상속됨 Exception)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetObjectData(SerializationInfo, StreamingContext)

파생 클래스에서 재정의된 경우 예외에 관한 정보를 SerializationInfo 에 설정합니다.

(다음에서 상속됨 Exception)
GetType()

현재 인스턴스의 런타임 형식을 가져옵니다.

(다음에서 상속됨 Exception)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 예외에 대한 문자열 표현을 만들고 반환합니다.

(다음에서 상속됨 Exception)

이벤트

SerializeObjectState
사용되지 않습니다.

예외에 대한 serialize된 데이터가 들어 있는 예외 상태 개체가 만들어지도록 예외가 serialize될 때 발생합니다.

(다음에서 상속됨 Exception)

적용 대상

추가 정보