CmtWaitForThreadPoolFunctionCompletion
int CmtWaitForThreadPoolFunctionCompletion (CmtThreadPoolHandle poolHandle, CmtThreadFunctionID threadFunctionID, unsigned int options);
Purpose
![]() |
Note This function has been superseded by CmtWaitForThreadPoolFunctionCompletionEx. |
Waits for the specified Thread Function to finish executing.
Instead of using this function to wait for a thread to complete, you can use CmtScheduleThreadPoolFunctionAdv to specify a callback function that is called when the Thread Function finishes executing.
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 CmtWaitForThreadPoolFunctionCompletion and the thread pool function thread both use ActiveX functions, a deadlock between the two threads could occur. Even if you call CmtWaitForThreadPoolFunctionCompletion with the OPT_TP_PROCESS_EVENTS_WHILE_WAITING option, multithreaded-style threads may deadlock.
Apartment-threaded style threads always own a window and use the message queue, instead of locks, to synchronize access to COM. Waiting on apartment-threaded style threads with the OPT_TP_PROCESS_EVENTS_WHILE_WAITING option 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 | The handle you obtained from CmtNewThreadPool to identify the thread pool. Pass DEFAULT_THREAD_POOL_HANDLE to specify the default thread pool. |
||
threadFunctionID | CmtThreadFunctionID | The threadFunctionID that you obtained from CmtScheduleThreadPoolFunction or CmtScheduleThreadPoolFunctionAdv.
|
||
options | unsigned int | Pass OPT_TP_PROCESS_EVENTS_WHILE_WAITING if you want this function to process events while waiting for the Thread Function to finish executing. Pass 0 if you do not want this function to process events while waiting. Any thread that creates a panel or window and does not destroy it must process events while it is waiting. If the thread does not process events while it is waiting, the system might hang. To avoid hanging the system, pass OPT_TP_PROCESS_EVENTS_WHILE_WAITING if this function might wait for more than a fraction of a second or if the thread you are waiting for sends messages or displays panels or dialog boxes.
|
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 CmtWaitForThreadPoolFunctionCompletion function:
- apps\daqmthread\daqMT.cws
Open example
- utility\threading\Simple\Simple.cws
Open example
- utility\threading\ThreadedGuessers\ThreadedGuessers.cws
Open example
- utility\threading\ThreadLocalVar\ThreadLocalVar.cws
Open example
- utility\threading\ThreadPool\ParallelTestInit\ParallelTestInit.cws
Open example
- utility\threading\ThreadSafeQueue\Overflow\Overflow.cws
Open example