LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple function with multithreading

Hi

I'm working on a multithreaded application. All threads will execute the same function which calls couple of subroutines. How do I configure the program so that each thread uses its own copy of those subroutines?

Thanks
0 Kudos
Message 1 of 3
(3,205 Views)

Calling a function from different threads usually does not require (the OS) to load the code more than once into memory. How code executes is controlled by the operating system, too.

Usually your data will mess up when it uses global variables in multiple threads.
As long as you use (non-static) local variables in your function, each thread/function creates an individual set of locals.
If the subroutines are not thread-safe (e.g. writing to global variables), there is only a small chance that your code will run as expected ...

Note:
You must be careful when dealing with shared resources in your functions/subroutines.

So: There is no chance to simply say "use an own copy of the subroutines". Please let me know Why do you think that you'd need a setting like this?
Regards, Guenter

Finally: The NI Developer Zone and this forum contain lots of articles dealing with multi-threading.

0 Kudos
Message 2 of 3
(3,197 Views)
 

I agree with Guenter's post. To get you started with the tutorials he mentioned at the end, I have posted a link below:

Multithreading in LabWindows/CVI


Regards,

 
Message 3 of 3
(3,171 Views)