01-19-2017 09:28 PM
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 ?
01-19-2017 09:55 PM
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
01-20-2017 12:51 AM
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.
01-20-2017 09:42 AM - edited 01-20-2017 09:45 AM
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
2) asynchronous subvi call that tries to connect to a device
[edit] added link [/edit]
01-20-2017 10:37 AM - edited 01-20-2017 10:41 AM
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...
Edit:
See this discusion to learn about "Treadconfig" which is a utility that will let you configure the number of threads.
Ben
01-20-2017 12:00 PM
@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.
01-20-2017 03:31 PM
@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