LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CmtInstallTSQCallback help

Hi i am using a thread safe queue but wish to execute the callback in another thread

so instead of passing
CmtGetCurrentThreadID() to CmtInstallTSQCallback I need to pass a thread id.

like

CmtInstallTSQCallback (tsqHandle, EVENT_TSQ_ITEMS_IN_QUEUE,
                                            600, QueueCallback, NULL,
                                            thread_id, &plotDataCallbackID);

How can I create a thread and get its id to pass to
CmtInstallTSQCallback.

Sorry if this has been answered. I can't find any examples of this.

Thanks

Glenn Pierce
0 Kudos
Message 1 of 3
(3,552 Views)

Hi Glenn

I have been looking into the CVI functions for multithreading and I don't think you can find the thread ID of any threads other than the current thread or the main thread. There is a CVI function that finds the ID of the main thread, this is the CmtGetMainThreadID function. You may be able to use C commands to do this, however there is no specific CVI function that can do this.

Also, having looked at the functions, it seems that you can create a thread pool which contains threads, but I don't think you can create an individual thread. You can us the CmtScheduleThreadPoolFunction to assign tasks. The function will automatically choose which task is assigned to which thread. Another function you can look at is the CmtScheduleThreadPoolFunctionAdv, this allows you assign priorities to functions.

I hope this helps

Regards

Beejal S
NI UK & Ireland
0 Kudos
Message 2 of 3
(3,491 Views)
Here is some pseudo code for passing a thread ID for the TSQ callback. Hope this helps.
 
volatile unsigned int threadID = 0; // global variable for thread ID
volatile int quitThread = 0; // global variable to signal thread function
 
Main thread:
CmtNewTSQ
CmtNewThreadPool
CmtScheduleThreadPoolFunction
while (threadID == 0) // wait for thread pool function to initialize its thread ID
    Sleep(0);
CmtInstallTSQCallback // install TSQ callback with threadID
/* do work */
CmtWaitForThreadPoolFunctionCompletion // wait for thread pool function to finish
//clean up
 
Thread Function:
threadID = CmtGetCurrentThreadID();
while (!quitThread)
    ProcessSystemEvents();
0 Kudos
Message 3 of 3
(3,478 Views)