From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how can i dynanic create threads in labview

hi guys,

i know labview is a nature muti-threads program, but it threads is fixed when programe finished.

i want to dynanic create threads in labview, but i don't konw how to do it ?

Labview 7.0, 8.0, 8.6,8.6.1,2011
0 Kudos
Message 1 of 7
(4,472 Views)

I tell my students to think about what they want to do, and not worry so much about how they do it.  You are focused on the "how" (see the first word of your Subject) -- why not tell us what you want to do, that is, what kind of problem you are contemplating?  Why is this question an issue for you?

 

Bob Schor

Message 2 of 7
(4,448 Views)

Thank for you replay.

My application is commucate to another devices through ethernet, but the number of devices was not fixed, it could be setting by user. I used to do this by using the structure "For Loop" in labview, but when one device "time out" will influence other device.

In short, i want to deal with the problem is when one device time out would not effect other device.

Mybe the best way to deal this problem is using muti-threads, each communicate using one thread. But the number of devices can be setting by user, i realize maybe i can use something called "thread-pool" just like it used in VC or java. so the problem is how can i dynanic create threads in labview.

 

 

Labview 7.0, 8.0, 8.6,8.6.1,2011
0 Kudos
Message 3 of 7
(4,425 Views)

hi kkjmt!

the "how a timeout of one/multiple influences other devices" is not quite clear from your description.

 

but two possible ways come to mind:

 

1) parallel execution of your array

  • right click on the for-loop and have a look at "configure iteration parallelism"
  • note that the loop will only finish when all iterations have finished

 

2) asynchronous subvi call that tries to connect to a device

 

[edit] added link [/edit]


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 4 of 7
(4,386 Views)

In this nugget years ago I used the challenge of creating an unspecified number of occurences as a platorm to introduce the idea of creating multiple processes.

 

That nugget used the theme "how do I dreate a real-life anamusic machine.

 

 

I used VI Server to create mutltiple porcesses each associated with a possilbe drum, pipe etc.

 

The follow-up discusion of that nugget touched on may ideas related to parallel processing and I welcome your review of that thread.

 

Re:Threads

 

Parallel processes and multiple threads are related but not exaxtly the same thing. LabVIEW will break up code into multiple threads based on the structure of the diagram where each "clump" (section of code that are independent of all other code) are allocated threads.

 

The modern version of the code I posted in that nugget could use asyncronouse Call By Breference nodes.

 

Regardless of how the processes are created you will still have to give some thought to "how do I communicate with a process that I do not know about at developemnt time?". But that is another story...

 

Spoiler
Think Queues or user events

 Edit:

See this discusion to learn about "Treadconfig" which is a utility that will let you configure the number of threads.

 

Ben  

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 5 of 7
(4,371 Views)

@kkjmt wrote:

Thank for you replay.

My application is commucate to another devices through ethernet, but the number of devices was not fixed, it could be setting by user. I used to do this by using the structure "For Loop" in labview, but when one device "time out" will influence other device.

In short, i want to deal with the problem is when one device time out would not effect other device.

Mybe the best way to deal this problem is using muti-threads, each communicate using one thread. But the number of devices can be setting by user, i realize maybe i can use something called "thread-pool" just like it used in VC or java. so the problem is how can i dynanic create threads in labview.

 

 


Have you tried some error handling at the time of error?

 

Like error check for a timeout, if true do something about it, then erase the error from the error cluster. 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 6 of 7
(4,353 Views)

@kkjmt wrote:

Thank for you replay.

My application is commucate to another devices through ethernet, but the number of devices was not fixed, it could be setting by user. I used to do this by using the structure "For Loop" in labview, but when one device "time out" will influence other device.

In short, i want to deal with the problem is when one device time out would not effect other device.

 


We do this.  We have a routine that monitors behavior with a 30fps video IP camera that takes 5-10 sec videos when triggered by a particular behavior (which occurs every 3-5 minutes).  So our "unit of study" is one camera, one subject, one trigger, producing one set of AVI files.

But we want to do this for 24 subjects simultaneously (assuming all 24 camera, triggers, etc. work), and want the 24 "streams" to run more-or-less independently of each other.  As others have mentioned, we do this by writing a single VI that runs one "Station" (camera, trigger, set of files/folders for output).  We then start 24 "clones" of this VI using Start Asynchronous Call.  LabVIEW "does its magic" and apportions CPU threads as it needs to "share the CPU" as equitably as possible among all of the processes.  If one of the Stations throws an Error (the Camera stops working, or the data disk fills up), that particular VI stops running, and now there are fewer processes ("threads") demanding CPU time.

 

So I'll add my Vote to the notion that a good way to have multiple processes share CPU resources is to use LabVIEW's "DataFlow Parallelism" and run independent asynchronous VIs either through VI Server or through Start Asynchronous Call.  Let LabVIEW worry about thread allocation -- you worry about writing efficient and "correct" code.

 

Bob Schor

0 Kudos
Message 7 of 7
(4,331 Views)