LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

The question about the callbackdata parameter in the function PostDeferredCallToThread()

I find if using a local variable to pass to the PostDeferredCallToThread(), then in the callback function, it cannot be recevied correctly. But as NI document said, this variable is a user-defined, will avoid declaring the data object as a global variable. how to interpret the question?

 

David

0 Kudos
Message 1 of 4
(4,389 Views)
If you provide a pointer to the function the variable pointed by the pointer must be still in memory if you want to access it from that thread function.
One way of keeping the variable "alive" when you leave the scope of a function is to define it as static.

Dynamically allocated memory (malloc/calloc) is also accessible if not freed.
Suggested reading:
http://gribblelab.org/CBootcamp/7_Memory_Stack_vs_Heap.html
S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 4
(4,378 Views)

That also be the 'GLOBAL' .

0 Kudos
Message 3 of 4
(4,343 Views)

Sure, global variables can be used.

 

But I did not mention it since you asked how you can avoid the global variable.

S. Eren BALCI
IMESTEK
0 Kudos
Message 4 of 4
(4,340 Views)