09-26-2012 09:25 AM
I'm just going to use queue messages instead 😃 For what it worth, I have been using locals for a long time and have never had any problems with them what so ever. You just have to use common sense when using them in other threads. I just use them to read data from other tasks to update indicators and so forth and have never had 1 problem with that part of it at all.
Thanks..
09-26-2012 09:29 AM
@QRP wrote:
I'm just going to use queue messages instead 😃 For what it worth, I have been using locals for a long time and have never had any problems with them what so ever. You just have to use common sense when using them in other threads. I just use them to read data from other tasks to update indicators and so forth and have never had 1 problem with that part of it at all.
Thanks..
Lack of evidence is not envidence of absence.
Ben
09-26-2012 10:10 AM
Oh there's evidence, because it works and that is enough for me. I don't have hours upon hours to waste to trying to find ways to make something fail since you don't make any money that way. If it works you go with it, if not you find another way. That simple 😃
09-26-2012 10:16 AM
@QRP wrote:
Oh there's evidence, because it works and that is enough for me. I don't have hours upon hours to waste to trying to find ways to make something fail since you don't make any money that way. If it works you go with it, if not you find another way. That simple 😃
Until you get a new computer and suddenly nothing works.
I was given a program that worked perfectly in a test system that we made 8-10 years ago. I was told to make small tweaks to add some functionality for a new test set. I ended up totally rewriting it. Disgruntled with me that I was taking so long, the coworker who wrote the original code put the original code on the new system. And it didn't work. Local variables causing race conditions left and right. They weren't so disgruntled with me after that.
09-26-2012 10:32 AM
So would this ever cause a problem? I have never seen any problem just reading data with a local this way.
09-26-2012 10:48 AM
Based on that example, an event structure would suit your needs a lot better. But it also depends on what else you have happening.
99% of the time when I use locals, it is to write a value to an indicator in different states of my state machine or event structure or reading a control in the exact same structure. But they are always in the same loop and therefore race conditions do not exist. If you are using a local in multiple loops, there is likely to be an issue. Of course, there are exceptions.
09-26-2012 11:10 AM
Oh Ok, this was just an example, but what you said is pretty much what I'm doing currently. I personally don't really see how you could elimnate using locals all together since you would have wiring nighmare. I do have a VI with 3 timed loops running as threads with indendant data clusters that are polling on hardware and I have a main thread state machine monitoring the threads status. I have used locals in the main statemachine just to read some of the threads data to post as indicaters and it has never failed that way at all for me. Do you see a problem with doing this? If yes, how could I change the state machine to monitor and update indicators and monitor some of the threads data without the local approach for just reads? Maybe an example would be nice... 😃
Thanks for your time.
09-26-2012 11:20 AM
@QRP wrote:
Oh Ok, this was just an example, but what you said is pretty much what I'm doing currently. I personally don't really see how you could elimnate using locals all together since you would have wiring nighmare. I do have a VI with 3 timed loops running as threads with indendant data clusters that are polling on hardware and I have a main thread state machine monitoring the threads status. I have used locals in the main statemachine just to read some of the threads data to post as indicaters and it has never failed that way at all for me. Do you see a problem with doing this? If yes, how could I change the state machine to monitor and update indicators and monitor some of the threads data without the local approach for just reads? Maybe an example would be nice... 😃
Thanks for your time.
Wiring nightmares only happen (to me, anyways) if clusters are used only sparingly. Wires help keep me disciplined in my coding. 😉
09-26-2012 12:25 PM
If you have wiring nightmares or require lots of locals it is generally a sign of a poor programming architecture. I work on large systems (1000s ov VIs) and very rarely use locals. They are generally only used in UI code. Also, any of our code that starts to look messy will get refactored so we have clean code. It is much easier to maintain and extend. Here is a typical looking block diagram.
09-26-2012 02:16 PM
If you don't use subVI's for whatever reason, you can try with a queue. If you care only about the latest cluster value, you can use 'loose enqueue' and 'preview queue element'. The error handling can be improved, this here is just an example. See the attached file.
Nick