LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use utility functions in multithreaded applications

For a CVI 7.1 multithreaded application, I would like to confirm the following notion. I would like to have a
MT app which would test several devices, each it is own thread. But there are several functions that I need to
analyze the results and I am wondering about how to use them. If the analysis function is called from a thread,
will it be its own copy? What happens if another thread calls the same function with different data? An app eng
from NI thought that so long as I pass data, that there would be not trouble, but I was wondering how others solved
the problem of multiple threads using the same analyzing functions.
Thanks
0 Kudos
Message 1 of 2
(2,776 Views)
> If the analysis function is called from a thread, will it be its own copy?

If you call a function from two threads simultaneously, there will be one "copy" of the instructions used execute the function and ony copy of any static data specified in the function (specified using the static keyword). This is the only data that will be shared between the two calls. Any stack variables and function parameters will have a unique instance for each call and will exist in distinct memory spaces; these will cause no problems with threading. The only time you will have a problem is when using "stateful" functions (such as rand()) which employ static data.

The other thing to consider is the sharing of hardware resources; if each thread tries to access the same hardware resource simultaneously, you will most likely have problems. Assuming you serialize access to hardware though, you should be fine.

Regards,

Alex
Message 2 of 2
(2,764 Views)