# CmtNewThreadPool

int CmtNewThreadPool (int maximumNumber_ofThreads, int *poolHandle);

## Purpose

Creates a thread pool.

The threads are not created until you schedule a function with CmtScheduleThreadPoolFunction or CmtScheduleThreadPoolFunctionAdv or you call CmtPreAllocThreadPoolThreads.

You do not need to create a thread pool if your program uses the only default thread pool. To use the default thread pool, pass DEFAULT_THREAD_POOL_HANDLE to the thread pool functions.

Call CmtDiscardThreadPool to free the thread pool resources when you finish using the thread pool.

## Parameters

Input
Name | Type | Description
maximumNumber_ofThreads | integer | The maximum number of threads in the thread pool. Call CmtGetThreadPoolAttribute or CmtSetThreadPoolAttribute with the ATTR_TP_MAX_NUM_THREADS attribute to read or change this value after the pool has been created. Use either a fixed number of threads or make the maximum number of threads proportional to the number of processors. For example, the maximum number or threads in the default thread pool is 2 + (2 * (number of processors)). Call CmtGetNumProcessors to determine the number of processors at run time. Pass UNLIMITED_THREAD_POOL_THREADS to indicate no limit on the maximum number of threads. In general, this is not recommended because having too many threads in a process can result in poor program performance.
Output
Name | Type | Description
poolHandle | integer | The handle that you use to identify the thread pool in subsequent function calls. The handle is never 0. Call CmtDiscardThreadPool to free the thread pool resources when you finish using the thread pool.

## Return Value

Name | Type | Description
CmtStatus | integer | The CmtStatus code that the function call returns. This function returns 0 to indicate success and negative values to indicate failure. Pass the CmtStatus code to CmtGetErrorMessage to get a description of the error code.