LabWindows/CVI

Content Type
Programming Language
Current manual
Table of Contents

CmtDiscardThreadPool

CmtDiscardThreadPool

int CmtDiscardThreadPool (CmtThreadPoolHandle poolHandle);

Purpose

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

CmtDiscardThreadPool waits for all scheduled thread functions to finish, even if they have not yet begun executing, before discarding the thread pool. 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_InitActiveXThreadStyleForCurrentThreadCA_InitActiveXThreadStyleForCurrentThread to set the ActiveX threading style for a thread.

Parameters

Input
Name Type Description
poolHandle CmtThreadPoolHandle 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 int 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.

Additional Information

Library: Utility Library

Include file: utility.h

LabWindows/CVI compatibility: LabWindows/CVI 5.5 and later

Examples

Refer to the following examples that use the CmtDiscardThreadPool function:

  • utility\threading\ThreadedGuessers\ThreadedGuessers.cws

    Open example
  • utility\threading\ThreadLockTimeout\ThreadLockTimeout.cws

    Open example
  • utility\threading\ThreadPool\MultiPanel\MultiPanel.cws

    Open example
  • utility\threading\ThreadPool\OnePanel\OnePanel.cws

    Open example
  • utility\threading\ThreadPool\ParallelTestInit\ParallelTestInit.cws

    Open example
Was this information helpful?