LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

What is difference between a ThreadFunctionID and a ThreadID?

CmtScheduleThreadPoolFunctionAdv(
TestThreadPoolHandle,
Tests_Start,
NULL,
THREAD_PRIORITY_NORMAL,
Tests_Finished,
EVENT_TP_THREAD_FUNCTION_END,
NULL,
CmtGetCurrentThreadID(),
&ThreadFunctionID);

CmtScheduleThreadPoolFunctionAdv returns a ThreadFunctionID for the new thread. What is the difference between this and the ThreadID that one gets if you use CmtGetCurrentThreadID() in the function Tests_Start?
0 Kudos
Message 1 of 2
(2,622 Views)
The thread ID refers to the thread, the threadFunctionID refers to the function running inside the thread. CVI uses intelligent thread management to help you avoid overhead of creating and killing worker threads. The thread pools do this. For example, if you create a thread pool and schedule a function to run in that pool, a thread is created and used for that function. When that function finishes, the thread pool doesn't destroy that thread, it just sets that thread to idle, so if you schedule another function in that thread pool, it can use the thread that already exists to run the function without having to creat a new thread which has some overhead. Since we do this, if you wanted to check to see if one of your functions was finished from a main threa
d, you couldn't just check the threadID to see if the thread was gone, you would need to check the threadFunctionID to see if it was running or not. However, if you wanted to kill a specific thread, you couldn't do it with the threadFunctionID, you would need the threadID since you wouldn't know if the function was still running.

Typical applications, you won't need to use either ID, functionID or threadID. The CVI thread management will usually take care of everything you need to do for you. That hopefully explains the difference between the threadfunctionID and the threadID though.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 2
(2,622 Views)