CmtWaitForThreadPoolFunctionCompletionEx
- Updated2023-02-21
- 3 minute(s) read
CmtWaitForThreadPoolFunctionCompletionEx
int CmtWaitForThreadPoolFunctionCompletionEx (CmtThreadPoolHandle poolHandle, CmtThreadFunctionID threadFunctionID, unsigned int options, unsigned int timeout);
Purpose
Waits for the specified Thread Function to finish executing, or times out after the value specified in the Timeout parameter.
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 CmtWaitForThreadPoolFunctionCompletionEx and the thread pool function thread both use ActiveX functions, a deadlock between the two threads could occur. Even if you call CmtWaitForThreadPoolFunctionCompletionEx 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.
|
||
timeout | unsigned int | Pass the number of milliseconds this function should wait. Pass CMT_WAIT_FOREVER if you want this function to wait forever. |
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 2010 and later