ThreadPool.GetMinThreads(Int32, Int32) 메서드

정의

스레드 생성 및 소멸을 관리하기 위한 알고리즘으로 전환하기 전에 새 요청에 따라 스레드 풀이 만드는 스레드의 최소 개수를 검색합니다.

public:
 static void GetMinThreads([Runtime::InteropServices::Out] int % workerThreads, [Runtime::InteropServices::Out] int % completionPortThreads);
public static void GetMinThreads (out int workerThreads, out int completionPortThreads);
static member GetMinThreads : int * int -> unit
Public Shared Sub GetMinThreads (ByRef workerThreads As Integer, ByRef completionPortThreads As Integer)

매개 변수

workerThreads
Int32

이 메서드가 반환될 때 스레드 풀에서 필요할 때 만드는 작업자 스레드의 최소 개수가 포함됩니다.

completionPortThreads
Int32

이 메서드가 반환될 때 스레드 풀에서 필요할 때 만드는 작업자 스레드의 최소 개수가 포함됩니다.

예제

다음 예제에서는 작업자 스레드의 최소 수를 4로 설정하고 비동기 I/O 완료 스레드의 최소 수에 대한 원래 값을 유지합니다.

using namespace System;
using namespace System::Threading;
int main()
{
   int minWorker;
   int minIOC;
   
   // Get the current settings.
   ThreadPool::GetMinThreads( minWorker, minIOC );
   
   // Change the minimum number of worker threads to four, but
   // keep the old setting for minimum asynchronous I/O
   // completion threads.
   if ( ThreadPool::SetMinThreads( 4, minIOC ) )
   {
      
      // The minimum number of threads was set successfully.
   }
   else
   {
      
      // The minimum number of threads was not changed.
   }
}
using System;
using System.Threading;

public class Test
{
    public static void Main()
    {
        int minWorker, minIOC;
        // Get the current settings.
        ThreadPool.GetMinThreads(out minWorker, out minIOC);
        // Change the minimum number of worker threads to four, but
        // keep the old setting for minimum asynchronous I/O 
        // completion threads.
        if (ThreadPool.SetMinThreads(4, minIOC))
        {
            // The minimum number of threads was set successfully.
        }
        else
        {
            // The minimum number of threads was not changed.
        }
    }
}
Imports System.Threading

Public Class Test

    <MTAThread> _
    Public Shared Sub Main()
        Dim minWorker, minIOC As Integer
        ' Get the current settings.
        ThreadPool.GetMinThreads(minWorker, minIOC)
        ' Change the minimum number of worker threads to four, but
        ' keep the old setting for minimum asynchronous I/O 
        ' completion threads.
        If ThreadPool.SetMinThreads(4, minIOC) Then
            ' The minimum number of threads was set successfully.
        Else
            ' The minimum number of threads was not changed.
        End If
    End Sub
End Class

설명

스레드 풀은 각 범주에 대한 최소값에 도달할 때까지 요청 시 새 작업자 스레드 또는 I/O 완료 스레드를 제공합니다. 기본적으로 최소 스레드 수는 시스템에서 프로세서의 수로 설정됩니다. 최소값에 도달하면 스레드 풀은 해당 범주에 추가 스레드를 만들거나 일부 작업이 완료될 때까지 기다릴 수 있습니다. .NET Framework 4부터 스레드 풀은 시간 단위당 완료되는 작업 수로 정의된 처리량을 최적화하기 위해 스레드를 만들고 삭제합니다. 스레드가 너무 적으면 사용 가능한 리소스가 효율적으로 사용되지 않는 반면, 너무 많으면 리소스 경합이 증가할 수 있습니다.

참고

요구가 적을 때는 실제 스레드 풀 스레드 수가 최소값보다 작을 수 있습니다.

적용 대상

추가 정보