LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with multithread

Hello!
I am trying to make two pair of buttons that are used to control a signal accquiring channel and a DO channel respectively to function independently. To do so, I put the progrommes for each button into seperate event structures, by which I think that the progrom will excute in four different threads. But when I excuted the program, something strange happened. The buttons didn't seam to able to function independently, but serially acutally. Because any button could only be excuted again only after other buttons had been pressed. So, I am stuck.  Why??????
Here is my source code edited in Labview 8.
0 Kudos
Message 1 of 8
(3,234 Views)
The short answer is that LV does not multithread within a VI, and multiple event structures in the same VI generally do not play together well.  A better architecture for what you're trying to do would be a single event structure containing all the buttons which in turn activates independent loops for each hardware activity (i.e. one while loop for your DAQ and one for your DO).  Looking at your VI, I'd turn each of your event structures into while loops (except maybe the stop functionality, that can stay in the event handler), add all of the buttons to one event handler, and upon detecting a button press event, send a message (queue, notifier, occurrence, whatever) to the appropriate while loop to start the timed loop.
Message 2 of 8
(3,226 Views)

Hi Traeger,

Your reply is top notch but I would like to split hairs over the phrase "...LV does not multithread within a VI, ...".

I believe this to be false.

The issue is proably related to

1) The events being configured to "Lock FP until event completes" or

2) The Event structure running in the UI thread (not sure on this point) which is single threaded by default.

Sorry about the hair-splitting but when a reply is SO correct, there is a danger of someone getting the wrong impression.

5-stars to you (to make up for my hair-splitting) Smiley Wink

Ben

 

 

Message Edited by Ben on 09-07-2006 10:51 AM

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 3 of 8
(3,218 Views)
Your code is not inside a while loop, thus I assume you are running this using the "continuous run" button. This is more of a debugging feature and has no use in any serious program! What basically happens is that once the program is all finished, it gets restarted automatically.
 
In your case, the program is only finished once ALL events have executed, leading to the observed behavior. A quick a (very!) dirty solution would be to place each event structure into its own while loop so each event can recycle independently.
 
A single VI can multithread just fine!
 
Have a look at some of the example programs that ship with LabVIEW.
 
0 Kudos
Message 4 of 8
(3,211 Views)
Sorry, I think I was being a bit too literal.  You can perform parallel tasks within a VI, there's no question about that.  Parallel while loops, however, do not execute in separate threads (as far as I know).  If you wish to force separate threads on your program, you need to encapsulate each thread's activity in its own VI and use the VI Execution Options to define which VIs operate in which thread.  In general, VIs default to running in the normal priority/UI thread.
0 Kudos
Message 5 of 8
(3,194 Views)

Trager wrote "Parallel while loops, however, do not execute in separate threads (as far as I know).  "

They can execute in parallel threads.

Please see this KB article on hyperthreading

http://zone.ni.com/devzone/conceptd.nsf/webmain/01F2E634710FB8E486256E2900586D41

The section labeled "Primes Parallelism Example" include the sentance;

"

 The LabVIEW dataflow programming paradigm allows the LabVIEW execution system to run the two loops in different threads.

"

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 8
(3,184 Views)

Got it.  I was thinking of the pre-LV7 definition of threads, where one execution system/priority combination was assigned a single thread.  It is still true that if you want to explicitly cause thread separation, you have to use the VI Execution Options (as opposed to the implicit separation that LV does when you have to independent running loops in the same VI).

I note that the same KB mentions a 4 thread limit per exec system.  Is that still the case in LV8?  It also states that that 4 thread limit is the default, but I don't know if/when that can be changed.  I'm interested in finding out, however.

0 Kudos
Message 7 of 8
(3,179 Views)

I have to run now but this came from the LV 7.1 upgrade notes.

"

To change how LabVIEW allocates threads, use the

threadconfig.vi in

the

vi.lib\Utility\sysinfo.llb. You also can disable reentrancy for

VIs by removing the checkmark from the

Reentrant execution checkbox

in the

Execution page of the VI Properties dialog box.

"

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 8
(3,171 Views)