LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I find all the TSQs in my application

I want to create a non-invasive diagnostic panel to my application. What I would like to find is a list of all the thread pools and TSQs in my application. This has to be done dynamically and I want a list of all the assigned handles. Is this possible in CVI 8.x? How?
0 Kudos
Message 1 of 3
(3,110 Views)
There are built in functions in LabWindows/CVI to retrieve the number of threads in the pool. There is no dynamically maintained queue of thread names, etc, so you would have to build this complex data type and maintain it yourself during runtime.

See the Utility Library>>Multithreading to access the available function panels for available multithreading functions.



Evan Prothro
RF Systems Engineer | NI

0 Kudos
Message 2 of 3
(3,088 Views)
There is no built in way to get these numbers/handles, though it should be fairly straightforward to do this yourself. The following code aliases the create/discard functions to wrapper functions that increment and decrement global count variables. You would just have to add the .c file to your project and include the header in any .c file that creates/discards thread pools or TSQs. Then you could just monitor the global variables to see how many queues/pools are alive. I realize you also wanted a list of the handles, but that's not much harder. You would have to keep lists instead of just ints, and you'd have to put locking (see the Cmt Thread Lock functions) around the list accesses for thread safety.

I have not tried or even compiled this code, but I believe it should work.

Also note that the default thread pool is not included in the thread pool count.

// begin new header, MTResourceCounting.h
#ifndef MT_RESOURCE_COUNTING_H
#define MT_RESOURCE_COUNTING_H
#include <utility.h>

#define CmtNewThreadPool        CmtNewThreadPoolWrapper
#define CmtDiscardThreadPool   CmtDiscardThreadPoolWrapper
#define CmtNewTSQ                   CmtNewTSQWrapper
#define CmtDiscardTSQ              CmtDiscardTSQWrapper

extern volatile int gThreadPoolCount;
extern volatile int gTSQCount;

int CVIFUNC     CmtNewThreadPoolWrapper(int maxNumThreads, int *poolHandle);
int CVIFUNC     CmtDiscardThreadPoolWrapper(int poolHandle);
int CVIFUNC     CmtNewTSQWrapper(int numItems, int itemSize, unsigned int options, int *queueHandle);
int CVIFUNC     CmtDiscardTSQWrapper(int queueHandle);

#endif
// end MTResourceCounting.h

// begin new source file, MTResourceCounting.c
#include <utility.h>

volatile int gThreadPoolCount = 0;
volatile int gTSQCount = 0;

int CVIFUNC     CmtNewThreadPoolWrapper(int maxNumThreads, int *poolHandle)
{
    int err = CmtNewThreadPool(maxNumThreads, poolHandle);
    if (err >= 0)
       ++gThreadPoolCount;
    return err;
}

int CVIFUNC     CmtDiscardThreadPoolWrapper(int poolHandle)
{
    int err = CmtDiscardThreadPool(poolHandle);
    if (err >= 0)
       --gThreadPoolCount;
    return err;
}

int CVIFUNC     CmtNewTSQWrapper(int numItems, int itemSize, unsigned int options, int *queueHandle)
{
    int err = CmtNewTSQ(itemSize, options, queueHandle);
    if (err >= 0)
       ++gTSQCount ;
    return err;
}

int CVIFUNC     CmtDiscardTSQWrapper(int queueHandle)
{
    int err = CmtDiscardTSQ(queueHandle);
    if (err >= 0)
       --gTSQCount ;
    return err;
}
// end MTResourceCounting.c
Message 3 of 3
(3,084 Views)