LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to pass data through multithreading pool callbacks?

Hi, nice to ask you guys again!!
Well, i've never used multithreading from labwindows before, and I started already, but I need to share data structures between threads and use a lock for that data to keep his integrity, but the problem is that the definition of a CVICALLBACK function for a thread pool has a pointer to void as a parameter data, and then in the definition I have to cast that void data to a specific data type, I tried to pass structures to a thread function to work with it, but i can't cast form void to the kind of my data structure.
?How i can pass small, medium and large data structures as a data parameter to a thread callback function and use in a threadpool?
I defined a structure like this:


typedef struct
{
int datatype1;
char *string;
float floatnumber;
}Typ_dataStructure;

I defined the thread function callback

int CVICALLBACK threadFunction(void *datafunction);

and in another part of the programm y scheduled the thread with the function defined:
Typ_dataStructure datastruct;
CmtScheduleThreadPoolFunction(????,threadFunction,(Typ_dataStructure*)datastruct,???)

But it doesnt work, i can use the data struct in the secondary thread at the same time i use it in the current thread
?What i can do?
0 Kudos
Message 1 of 2
(3,010 Views)
You should use our Thread Safe Variable functions for this. We have functions and macros to do what you would like to do. The example in \cvi\samples\utility\Threading\ThreadSafeVar will demonstrate how to use the macros. That example uses integers, but you can substitute your typedef'd structure for the int and use it instead. The example shows how to access a TSV through a pointer with the GetPointerTo macro, and how to access a local copy with the Get macro. If you use this method you will have a thread safe global variable for your structures that you can access by pointer.

Best Regards,

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