# CmtDiscardThreadPool

int CmtDiscardThreadPool (int poolHandle);

## Purpose

Destroys a thread pool and frees the resources used by it.

CmtDiscardThreadPool waits for all currently executing thread pool threads to finish before destroying them. If your Thread Functions are not guaranteed to finish executing, you must make sure that no active threads exist in the pool before calling this function. Call CmtGetThreadPoolAttribute with the ATTR_TP_NUM_ACTIVE_THREADS attribute to determine the number of active threads in the pool.

Do not call this function while you are inside a DLL DllMain function. If you call CmtDiscardThreadPool from DLLMain, your program will hang.

Threads initialized with the multithreaded ActiveX threading style internally wait on ActiveX/COM locks to synchronize access to ActiveX/COM servers and objects. If the thread that calls CmtDiscardThreadPool and one or more thread pool threads use ActiveX functions, a deadlock between the threads could occur.

Apartment-threaded style threads always own a window and use the message queue, instead of locks, to synchronize access to COM. Using apartment-threaded style threads tends to prevent deadlocks.

| Note Call CA_InitActiveXThreadStyleForCurrentThread CA_InitActiveXThreadStyleForCurrentThread to set the ActiveX threading style for a thread.

## Parameters

Input
Name | Type | Description
poolHandle | integer | Pass the handle you obtained from CmtNewThreadPool to identify the thread pool. Do not pass DEFAULT_THREAD_POOL_HANDLE to this function.

## 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.