LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

The REAL multithread in LabView

Hello,
 I am trying to do the next thing in Labview:
   I have two main processes in a loop: data aquisition by hardware, and processing of this aquired data. As I understand the idea of multithreading,
 it possible to  put these processes in a diffrent threads,in such a way, that While a  new data is aquired by hardware,the processor  does
 the processing of perviously aqured data.
       For example if aquisition  takes X seconds, and data processing takes X seconds too, so in a "direct" program it take 2*X *Number_Of_Loops seconds,
and in a multithread I would expect to get a X*Number_of_Loops seconds of execution (i don`t take in account the first and last aquisition).
       But, after several different approaches I cannot  realize this wonderful idea in LabView,somehow,it Always done consequantly.
  ( I did two differnt VI's , say "Aquire" and "Process",put them on a different threads, and did some manipulations with a While loop and other structures).
May be someone meet such a problem before,and knows the solution?
 
    Thanks.
_________________________________________________________________________________________________
LV 8.2 at Windows & Linux


0 Kudos
Message 1 of 4
(2,485 Views)



"mishklyar" <x@no.email> wrote in message news:1154612409355-399918@exchange.ni.com...
Hello,
&nbsp;I am trying to do the next thing in Labview:
&nbsp;&nbsp; I have two main processes in a loop: data aquisition by hardware,&nbsp;and processing of this aquired data. As I understand the idea of multithreading,
&nbsp;it possible to&nbsp;&nbsp;put these processes in a diffrent threads,in such a way, that&nbsp;While&nbsp;a&nbsp; new data is aquired by hardware,the processor&nbsp; does
&nbsp;the processing of perviously aqured data.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;For example if aquisition&nbsp; takes X seconds, and data processing takes X seconds too, so in a "direct" program it take 2*X *Number_Of_Loops seconds,
and in a multithread I would&nbsp;expect to get a X*Number_of_Loops&nbsp;seconds of execution (i don`t take in account the first&nbsp;and last&nbsp;aquisition).
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;But,&nbsp;after several different approaches&nbsp;I cannot &nbsp;realize this wonderful idea in LabView,somehow,it Always done consequantly.
&nbsp;&nbsp;( I did two differnt VI's , say "Aquire" and "Process",put them&nbsp;on a&nbsp;different threads, and did some manipulations with a While loop and other structures).
May be someone meet such a problem before,and knows the solution?
&nbsp;
&nbsp;&nbsp; &nbsp;Thanks.




You can never achieve this with one while loop.


You need two while loops. Next challenge it to synchronise the data between the two... Some like queues, others buffers, some use locals or globals (both not recommended, but ok for experiments). If you are an advanced user, you can use user events.


Another problem will be stopping the loop. Easiest way it to use a local. Nicest way is to use queues, buffer of user events...


With one loop, everything in it will be synchronised (just like in any other language). The loop won't run again before everything in it is finished.


This is very common problem. Every "above trivial" program has something like this. It's the first problem beginners will encounter. Next problem is to keep thing tidy. Read about state machines, queued stade machines, demons, producer/consumer to learn some ways to do this.


Regards,


Wiebe.
0 Kudos
Message 2 of 4
(2,471 Views)

Yes check out the producer consumer model.  The producer is your Data Acquisition and the consumer is the data processor.  If you use the queue status as the consumers loop termination condition you dont even need a local variable.  This is very nice because it ensures that the data acquisition is not lost but buffered in the queue for processing.  The processor thread is only going to consume CPU resources when unprocessed data is waiting so you dont have to balance the timing of the two loops.  If however the time to acquire is greater than the time to process you can get away with one loop and not worry about lost data.

 

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 3 of 4
(2,466 Views)
Thanks a lot
_________________________________________________________________________________________________
LV 8.2 at Windows & Linux


0 Kudos
Message 4 of 4
(2,460 Views)