SemaphoreFullException 클래스
정의
public ref class SemaphoreFullException : Exception
public ref class SemaphoreFullException : SystemException
public class SemaphoreFullException : Exception
public class SemaphoreFullException : SystemException
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public class SemaphoreFullException : SystemException
type SemaphoreFullException = class
inherit Exception
type SemaphoreFullException = class
inherit SystemException
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Serializable>]
type SemaphoreFullException = class
inherit SystemException
Public Class SemaphoreFullException
Inherits Exception
Public Class SemaphoreFullException
Inherits SystemException
- 상속
- 상속
- 특성
예제
다음 코드 예제에서는 한 스레드에서 프로그래밍 오류가 발생 하 여 다른 스레드에서를 수행 하는 방법을 보여 줍니다. SemaphoreFullException 두 스레드가 세마포를 입력 합니다.The following code example shows how a programming error in one thread can lead to a SemaphoreFullException in another thread: Two threads enter a semaphore. 두 번째 스레드는 세마포를 두 번 해제 하지만 첫 번째 스레드에서는 해당 작업을 계속 실행 합니다.The second thread releases the semaphore twice, while the first thread is still executing its task. 첫 번째 스레드가 완료 되 고 세마포를 해제 하면 세마포 수가 이미 꽉 차서 예외가 throw 됩니다.When the first thread finishes and releases the semaphore, the semaphore count is already full and an exception is thrown.
#using <System.dll>
using namespace System;
using namespace System::Threading;
public ref class Example
{
private:
// A semaphore that can satisfy at most two concurrent
// requests.
//
static Semaphore^ _pool = gcnew Semaphore( 2,2 );
public:
static void main()
{
// Create and start two threads, A and B.
//
Thread^ tA = gcnew Thread( gcnew ThreadStart( ThreadA ) );
tA->Start();
Thread^ tB = gcnew Thread( gcnew ThreadStart( ThreadB ) );
tB->Start();
}
private:
static void ThreadA()
{
// Thread A enters the semaphore and simulates a task
// that lasts a second.
//
_pool->WaitOne();
Console::WriteLine( L"Thread A entered the semaphore." );
Thread::Sleep( 1000 );
try
{
_pool->Release();
Console::WriteLine( L"Thread A released the semaphore." );
}
catch ( Exception^ ex )
{
Console::WriteLine( L"Thread A: {0}", ex->Message );
}
}
static void ThreadB()
{
// Thread B simulates a task that lasts half a second,
// then enters the semaphore.
//
Thread::Sleep( 500 );
_pool->WaitOne();
Console::WriteLine( L"Thread B entered the semaphore." );
// Due to a programming error, Thread B releases the
// semaphore twice. To fix the program, delete one line.
_pool->Release();
_pool->Release();
Console::WriteLine( L"Thread B exits successfully." );
}
};
/* This code example produces the following output:
Thread A entered the semaphore.
Thread B entered the semaphore.
Thread B exits successfully.
Thread A: Adding the given count to the semaphore would cause it to exceed its maximum count.
*/
using System;
using System.Threading;
public class Example
{
// A semaphore that can satisfy at most two concurrent
// requests.
//
private static Semaphore _pool = new Semaphore(2, 2);
public static void Main()
{
// Create and start two threads, A and B.
//
Thread tA = new Thread(new ThreadStart(ThreadA));
tA.Start();
Thread tB = new Thread(new ThreadStart(ThreadB));
tB.Start();
}
private static void ThreadA()
{
// Thread A enters the semaphore and simulates a task
// that lasts a second.
//
_pool.WaitOne();
Console.WriteLine("Thread A entered the semaphore.");
Thread.Sleep(1000);
try
{
_pool.Release();
Console.WriteLine("Thread A released the semaphore.");
}
catch(Exception ex)
{
Console.WriteLine("Thread A: {0}", ex.Message);
}
}
private static void ThreadB()
{
// Thread B simulates a task that lasts half a second,
// then enters the semaphore.
//
Thread.Sleep(500);
_pool.WaitOne();
Console.WriteLine("Thread B entered the semaphore.");
// Due to a programming error, Thread B releases the
// semaphore twice. To fix the program, delete one line.
_pool.Release();
_pool.Release();
Console.WriteLine("Thread B exits successfully.");
}
}
/* This code example produces the following output:
Thread A entered the semaphore.
Thread B entered the semaphore.
Thread B exits successfully.
Thread A: Adding the given count to the semaphore would cause it to exceed its maximum count.
*/
Imports System.Threading
Public Class Example
' A semaphore that can satisfy at most two concurrent
' requests.
'
Private Shared _pool As New Semaphore(2, 2)
<MTAThread> _
Public Shared Sub Main()
' Create and start two threads, A and B.
'
Dim tA As New Thread(AddressOf ThreadA)
tA.Start()
Dim tB As New Thread(AddressOf ThreadB)
tB.Start()
End Sub
Private Shared Sub ThreadA()
' Thread A enters the semaphore and simulates a task
' that lasts a second.
'
_pool.WaitOne()
Console.WriteLine("Thread A entered the semaphore.")
Thread.Sleep(1000)
Try
_pool.Release()
Console.WriteLine("Thread A released the semaphore.")
Catch ex As Exception
Console.WriteLine("Thread A: {0}", ex.Message)
End Try
End Sub
Private Shared Sub ThreadB()
' Thread B simulates a task that lasts half a second,
' then enters the semaphore.
'
Thread.Sleep(500)
_pool.WaitOne()
Console.WriteLine("Thread B entered the semaphore.")
' Due to a programming error, Thread B releases the
' semaphore twice. To fix the program, delete one line.
_pool.Release()
_pool.Release()
Console.WriteLine("Thread B exits successfully.")
End Sub
End Class
' This code example produces the following output:
'
' Thread A entered the semaphore.
' Thread B entered the semaphore.
' Thread B exits successfully.
' Thread A: Adding the given count to the semaphore would cause it to exceed its maximum count.
'
설명
세마포에 대 한 카운트는 스레드가 세마포에 진입할 때마다 감소 하며, 스레드가 세마포를 해제할 때 증가 합니다.The count on a semaphore is decremented each time a thread enters the semaphore, and incremented when a thread releases the semaphore. 개수가 0 인 경우 후속 요청은 다른 스레드가 세마포를 해제할 때까지 차단 됩니다.When the count is zero, subsequent requests block until other threads release the semaphore. 모든 스레드가 세마포를 해제 한 경우 세마포가 생성 될 때 지정 된 최대값에 개수가 있습니다.When all threads have released the semaphore, the count is at the maximum value specified when the semaphore was created. 프로그래밍 오류로 인해 스레드가 Semaphore.Release 이 시점에서 메서드를 호출 하면이 SemaphoreFullException throw 됩니다.If a programming error causes a thread to call the Semaphore.Release method at this point, a SemaphoreFullException is thrown.
참고
Semaphore클래스는 및 메서드에 대 한 호출에 스레드 id를 적용 하지 않습니다 WaitHandle.WaitOne Semaphore.Release .The Semaphore class does not enforce thread identity on calls to the WaitHandle.WaitOne and Semaphore.Release methods. 를 호출 하는 것과 동일한 스레드가 필요 하지 않습니다 WaitOne Release .It is not necessary for the same thread that called WaitOne to call Release.
SemaphoreFullException 는 예외가 발생 한 코드에 문제가 있음을 나타내는 것은 아닙니다.SemaphoreFullException does not necessarily indicate a problem with the code where the exception occurred. 스레드 A와 스레드 B의 최대 수가 2 인 세마포를 입력 하는 시나리오를 살펴보겠습니다.Consider the following scenario: Thread A and thread B enter a semaphore that has a maximum count of two. 스레드 B에서 프로그래밍 오류가 발생 하면 Release 세마포의 개수가 full이 되도록 두 번 호출 됩니다.A programming error in thread B causes it to call Release twice, so that the count on the semaphore is full. 결과적으로 스레드 A Release 가를 호출 하면 SemaphoreFullException 이 throw 됩니다.As a result, when thread A eventually calls Release, a SemaphoreFullException is thrown.
SemaphoreFullException 클래스의 인스턴스에 대한 초기 속성 값 목록은 SemaphoreFullException() 생성자를 참조하십시오.For a list of initial property values for an instance of the SemaphoreFullException class, see the SemaphoreFullException() constructor.
생성자
SemaphoreFullException() |
기본값을 사용하여 SemaphoreFullException 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the SemaphoreFullException class with default values. |
SemaphoreFullException(SerializationInfo, StreamingContext) |
serialize된 데이터를 사용하여 SemaphoreFullException 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the SemaphoreFullException class with serialized data. |
SemaphoreFullException(String) |
지정된 오류 메시지를 사용하여 SemaphoreFullException 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the SemaphoreFullException class with a specified error message. |
SemaphoreFullException(String, Exception) |
지정된 오류 메시지와 해당 예외의 원인인 내부 예외에 대한 참조를 사용하여 SemaphoreFullException 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the SemaphoreFullException class with a specified error message and a reference to the inner exception that is the cause of this exception. |
속성
Data |
예외에 대한 사용자 정의 정보를 추가로 제공하는 키/값 쌍 컬렉션을 가져옵니다.Gets a collection of key/value pairs that provide additional user-defined information about the exception. (다음에서 상속됨 Exception) |
HelpLink |
이 예외와 연결된 도움말 파일에 대한 링크를 가져오거나 설정합니다.Gets or sets a link to the help file associated with this exception. (다음에서 상속됨 Exception) |
HResult |
특정 예외에 할당된 코드화된 숫자 값인 HRESULT를 가져오거나 설정합니다.Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception. (다음에서 상속됨 Exception) |
InnerException |
현재 예외를 발생시킨 Exception 인스턴스를 가져옵니다.Gets the Exception instance that caused the current exception. (다음에서 상속됨 Exception) |
Message |
현재 예외를 설명하는 메시지를 가져옵니다.Gets a message that describes the current exception. (다음에서 상속됨 Exception) |
Source |
오류를 발생시키는 애플리케이션 또는 개체의 이름을 가져오거나 설정합니다.Gets or sets the name of the application or the object that causes the error. (다음에서 상속됨 Exception) |
StackTrace |
호출 스택의 직접 실행 프레임 문자열 표현을 가져옵니다.Gets a string representation of the immediate frames on the call stack. (다음에서 상속됨 Exception) |
TargetSite |
현재 예외를 throw하는 메서드를 가져옵니다.Gets the method that throws the current exception. (다음에서 상속됨 Exception) |
메서드
Equals(Object) |
지정된 개체가 현재 개체와 같은지 확인합니다.Determines whether the specified object is equal to the current object. (다음에서 상속됨 Object) |
GetBaseException() |
파생 클래스에서 재정의된 경우 하나 이상의 후속 예외의 근본 원인이 되는 Exception 을 반환합니다.When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions. (다음에서 상속됨 Exception) |
GetHashCode() |
기본 해시 함수로 작동합니다.Serves as the default hash function. (다음에서 상속됨 Object) |
GetObjectData(SerializationInfo, StreamingContext) |
파생 클래스에서 재정의된 경우 예외에 관한 정보를 SerializationInfo 에 설정합니다.When overridden in a derived class, sets the SerializationInfo with information about the exception. (다음에서 상속됨 Exception) |
GetType() |
현재 인스턴스의 런타임 형식을 가져옵니다.Gets the runtime type of the current instance. (다음에서 상속됨 Exception) |
MemberwiseClone() |
현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object. (다음에서 상속됨 Object) |
ToString() |
현재 예외에 대한 문자열 표현을 만들고 반환합니다.Creates and returns a string representation of the current exception. (다음에서 상속됨 Exception) |
이벤트
SerializeObjectState |
예외에 대한 serialize된 데이터가 들어 있는 예외 상태 개체가 만들어지도록 예외가 serialize될 때 발생합니다.Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception. (다음에서 상속됨 Exception) |