Admin Production ni-theme
Current Publication

CmtNewThreadPool

LabWindows/CVI

CmtNewThreadPool

int CmtNewThreadPool (int maximumNumberOfThreads, CmtThreadPoolHandle *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
maximumNumberOfThreads int 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 CmtThreadPoolHandle 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 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 CmtNewThreadPool 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