Thread Pool Class Help
- Updated2023-02-21
- 2 minute(s) read
Thread Pool Class Help
This class contains functions you can use to run code in separate threadsseparate threads using a LabWindows/CVI thread poolthread pool.
To use a thread pool, call the CmtScheduleThreadPoolFunction or CmtScheduleThreadPoolFunctionAdv functions and pass the name of the function that you want to execute in a secondary thread. The thread pool schedules your function for execution in one of its threads. Depending on the configuration and current state of the thread pool at the time you schedule your function, the thread pool creates a new thread in which to run your function, uses an existing idle thread to run your function, or waits until an active thread is finished and uses it to run your function.
The function that you pass to CmtScheduleThreadPoolFunction and CmtScheduleThreadPoolFunctionAdv is referred to as a thread function. Thread pool thread functions can have any name but must have the following prototype:
int CVICALLBACK ThreadFunction (void *functionData);
You can use the default thread pooldefault thread pool provided by the Utility Library or create a new thread pool for the thread pool functions. To use the default thread pool, pass DEFAULT_THREAD_POOL_HANDLE in the poolHandle parameter of the thread pool functions.
If you want to specify callbacks for or set the attributes for a thread pool, create a new thread pool. You can use the CmtNewThreadPool and CmtSetThreadPoolAttribute functions to create a new thread pool and customize its properties.
Call CmtDiscardThreadPool to clean up the thread pool.
![]() |
Note If you want to perform some operation in a timer callback that executes in its own thread, you can use the toolslib/toolbox/asynctmr.fp instrument driver. This timer uses its own thread to execute the timer callback and does not require you to create a thread or explicitly schedule a function in another thread. |
Library: Utility Library