ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multithreading in LabView loops doesn't work?

Hello everybody,
I wanted to test the independency and multithreading in LabView loops - I assumed that every loop in LabView is created on different thread so it's independent from another one. So I had the addidtional (test) DLL which had 2 functions: "start long task" - it was just an infinite loop within the DLL, and the second function "stop task" - which stopped this inifinte loop.
I have put call to "start long task" in one LabView loop, and the testing the button and stopping the loop (by calling the "stop task" DLL function) in another loop. But it didn't worked. After calling the "start long task" DLL function the LabView system just hanged and it was impossible to press a button or do anything. I had to
use the Process Manager and kill the LabView...
This DLL was also tested under the Visual C++ test program, and it worked - it was possible for user to cancel the loop in each moment.
So it seems the loops in LabView don't work in different thrads (at last when within loop there is a call to external DLL)? Or maybe I use wrong technique?
Can anyone help me with my problem?
TIA,
Yazilim
PS. I incude the source code of the test program as well as DLL.
0 Kudos
Message 1 of 7
(4,055 Views)
Hi,

Just by making two loops in a LabVIEW diagram will not start two threads (for each loop). They will run in the same thread. In LabVIEW, you can not start dynamic threads.

However, by putting the LabVIEW loops in a sub VIs. The main VI will then consist of two different subVIs, each containing a loop. Now, you could make the subVIs run in different thread by editing the VIs propertys under the selection "Execution" and there under "Preferred Execution System" select which thread the VI should execute under. By select for instance, "other1" for one subVI and "other2" for the other subVIs, you could have the two loops running in different threads.

This is the only way I could think of to solve your problem. I really hope that National Instrumen
ts support dynamic threads in LabVIEW7???

Best regards,
Mattias Ericsson
Endevo Sweden
Message 2 of 7
(4,055 Views)
> Just by making two loops in a LabVIEW diagram will not start two
> threads (for each loop). They will run in the same thread. In LabVIEW,
> you can not start dynamic threads.
>
....


>
> This is the only way I could think of to solve your problem. I really
> hope that National Instruments support dynamic threads in LabVIEW7???
>

If you are running on a multithreaded computer, then LV automatically
starts up one thread per execution system per processor.

Also, even with a single thread, LV will still multitask loops along
with all other parallel code, but it will do so cooperatively by using
code that is compiled into the VI.

Finally, if you go to vi.lib/utilities or someplace like that, there is
a VI for configuring how many threads LV mak
es for any given execution
system. If you would prefer to have several threads for the standard
execution system at standard priority.

Keep in mind that the more task switching that goes on, the more
overhead you will pay. This is the reason that LV still uses its
cooperative multitasking rather than having many many threads executing
in parallel by default.

Greg McKaskle
0 Kudos
Message 3 of 7
(4,055 Views)
Hi Greg,
Thanks for the answer. Can you please give me the exact name of the folder and the VI you've mentioned in your comment?
0 Kudos
Message 4 of 7
(4,055 Views)
> Thanks for the answer. Can you please give me the exact name of the
> folder and the VI you've mentioned in your comment?
>

vi.lib/Utility/sysinfo.llb/threadconfig.vi

The initial panel shows the configuration. The Configure button at the
bottom of the screen will bring up a VI/dialog to change things.


Greg McKaskle
0 Kudos
Message 6 of 7
(4,055 Views)
On Tue, 26 Feb 2002 02:00:23 GMT, Greg McKaskle wrote:
>>
>> This is the only way I could think of to solve your problem. I really
>> hope that National Instruments support dynamic threads in LabVIEW7???

What would be the benefit of operating system threads comnpared to
current system ?

Juha
0 Kudos
Message 5 of 7
(4,055 Views)
A few nodes or items on the block diagram are synchronous, meaning they do not multitask with other nodes. In a multithreaded application, they run to completion, and the thread in which they run is monopolized by that task until the task completes.

Code Interface Nodes (CINs), DLL calls, and computation functions run synchronously. Most analysis VIs and data acquisition VIs contain CINs and therefore run synchronously.

Almost all other nodes are asynchronous. For example, structures, I/O functions, timing functions, and subVIs run asynchronously.

============================
What you read was a part of NI application note on multithreading.

GoodLuck
0 Kudos
Message 7 of 7
(4,055 Views)