LazyThreadSafetyMode 열거형
정의
public enum class LazyThreadSafetyMode
public enum LazyThreadSafetyMode
type LazyThreadSafetyMode =
Public Enum LazyThreadSafetyMode
- 상속
필드
ExecutionAndPublication | 2 | 잠금을 사용하여 단일 스레드만 스레드로부터 안전한 방식으로 Lazy<T> 인스턴스를 초기화할 수 있도록 합니다.Locks are used to ensure that only a single thread can initialize a Lazy<T> instance in a thread-safe manner. 초기화 메서드(또는 초기화 메서드를 찾을 수 없습니다. 매개 변수가 없는 생성자)에서 내부적으로 잠금을 사용하는 경우 교착 상태가 발생할 수 있습니다.If the initialization method (or the parameterless constructor, if there is no initialization method) uses locks internally, deadlocks can occur. 초기화 메서드( |
None | 0 | Lazy<T> 인스턴스는 스레드로부터 안전하지 않습니다. 여러 스레드에서 인스턴스에 액세스하는 경우 해당 동작이 정의되어 있지 않습니다.The Lazy<T> instance is not thread safe; if the instance is accessed from multiple threads, its behavior is undefined. 고성능이 중요하며 Lazy<T> 인스턴스가 둘 이상의 스레드에서 초기화되지 않는 경우에만 이 모드를 사용합니다.Use this mode only when high performance is crucial and the Lazy<T> instance is guaranteed never to be initialized from more than one thread. 초기화 메서드( |
PublicationOnly | 1 | 여러 스레드에서 Lazy<T> 인스턴스를 동시에 초기화하려고 하면 모든 스레드에서 초기화 메서드(또는 초기화 메서드를 찾을 수 없습니다. 매개 변수가 없는 생성자)를 실행할 수 있습니다.When multiple threads try to initialize a Lazy<T> instance simultaneously, all threads are allowed to run the initialization method (or the parameterless constructor, if there is no initialization method). 초기화를 완료하는 첫 번째 스레드에서 Lazy<T> 인스턴스의 값을 설정합니다.The first thread to complete initialization sets the value of the Lazy<T> instance. 초기화 메서드에서 해당 스레드에 대한 예외가 발생하지 않는 경우 초기화 메서드를 동시에 실행하는 다른 모든 스레드에 해당 값이 반환됩니다.That value is returned to any other threads that were simultaneously running the initialization method, unless the initialization method throws exceptions on those threads. 경쟁하는 스레드에서 만든 모든 |
설명
이 열거형을 사용 하 여 지정 된 mode
의 매개 변수 Lazy<T> 생성자입니다.Use this enumeration to specify the mode
parameter of Lazy<T> constructors. 가지고 여부 또는이 열거형 측면에서 스레드 동기화에 대 한 모든 생성자의 효과 설명할 수 있습니다 mode
매개 변수입니다.The effects of all constructors on thread synchronization can be described in terms of this enumeration, whether or not they have mode
parameters.
Lazy<T>인스턴스는 사용자 지정 초기화 메서드나에 대 한 매개 변수가 없는 생성자에 의해 초기화 됩니다 T
.A Lazy<T> instance is initialized either by a user-specified initialization method or by the parameterless constructor for T
. 지정 된 초기화 메서드가 합니다 valueFactory
의 매개 변수를 Lazy<T> 생성자입니다.The initialization method is specified by the valueFactory
parameter of a Lazy<T> constructor. 인스턴스를 반환 하는 메서드 T
, 인스턴스에서 지연 초기화 되는 형식인 Lazy<T>합니다.The method returns an instance of T
, which is the type that is lazily instantiated by the instance of Lazy<T>. 생성자에 valueFactory
매개 변수가 없는 경우에 대 한 매개 변수가 없는 생성자를 T
사용 하 여 인스턴스를 초기화 합니다 Lazy<T> .If a constructor does not have a valueFactory
parameter, the parameterless constructor for T
is used to initialize the Lazy<T> instance. 두 경우 모두 초기화가 처음 호출 하면 발생 합니다 Lazy<T>.Value 속성입니다.In either case, initialization occurs the first time you call the Lazy<T>.Value property.
스레드 보안을 지정 하는 것 외에도 Lazy<T> 예외 캐싱을 하는 경우가이 열거형에 영향을 줍니다.In addition to specifying the thread safety of a Lazy<T> instance, this enumeration affects exception caching. 에 대 한 예외가 캐시 되 면을 Lazy<T> 인스턴스를 표시 한 번만 인스턴스를 초기화 합니다.When exceptions are cached for a Lazy<T> instance, you get only one chance to initialize the instance. 처음으로 예외가 발생 하는 경우 호출 하는 Lazy<T>.Value 예외가 캐시 되 고 모든 후속 호출에서 다시 throw 속성인은 Lazy<T>.Value 속성입니다.If an exception is thrown the first time you call the Lazy<T>.Value property, that exception is cached and rethrown on all subsequent calls to the Lazy<T>.Value property. 예외 캐싱을의 장점은 모든 두 스레드가 오류가 발생 하는 경우에 항상 동일한 결과 얻을 한다는 점입니다.The advantage of caching exceptions is that any two threads always get the same result, even when errors occur.
PublicationOnly 모드를 지정 하는 경우 예외가 캐시 되지 됩니다.When you specify the PublicationOnly mode, exceptions are never cached. None 또는 ExecutionAndPublication을 지정 하는 경우 캐싱은 초기화 메서드를 지정 하거나에 대해 매개 변수가 없는 생성자를 사용할 수 있는지 여부에 따라 달라 집니다 T
.When you specify None or ExecutionAndPublication, caching depends on whether you specify an initialization method or allow the parameterless constructor for T
to be used. 초기화 메서드를 지정하면 이 두 모드에 대해 예외 캐싱을 사용합니다.Specifying an initialization method enables exception caching for these two modes. 초기화 메서드는 매우 간단할 수 있습니다.The initialization method can be very simple. 예를 들어 T
new Lazy<Contents>(() => new Contents(), mode)
c #의 경우 또는 New Lazy(Of Contents)(Function() New Contents())
Visual Basic에서 매개 변수가 없는 생성자를 호출할 수 있습니다.For example, it might call the parameterless constructor for T
: new Lazy<Contents>(() => new Contents(), mode)
in C#, or New Lazy(Of Contents)(Function() New Contents())
in Visual Basic. 초기화 메서드를 지정 하지 않는 생성자를 사용 하는 경우에 대 한 매개 변수가 없는 생성자에서 throw 된 예외는 T
캐시 되지 않습니다.If you use a constructor that does not specify an initialization method, exceptions that are thrown by the parameterless constructor for T
are not cached. 다음 표에서 예외 캐싱 동작을 보여 줍니다.The following table summarizes exception caching behavior.
모드Mode | 초기화 메서드를 사용 하 여Using initialization method | 에 대해 매개 변수가 없는 생성자 사용 T Using parameterless constructor for T |
---|---|---|
NoneNone | 캐시됨Cached | 캐시되지 않음Not cached |
PublicationOnlyPublicationOnly | 캐시되지 않음Not cached | 캐시되지 않음Not cached |
ExecutionAndPublicationExecutionAndPublication | 캐시됨Cached | 캐시되지 않음Not cached |