10-24-2011 02:30 PM
Hello everyone,
I am having problems with writing data. I am taking some statistics from a bunch of .tdm files and recording them to a master file. I have all of that down, but the last part of the data is not written when the program is first run. When I run the program immediately afterwards, the last row of data from the first run is the first row of data recorded. I assume that the buffer that holds the array is not being emptied at the end of the program, but I do not know how to 'flush' an array or if such a method exists(I know it does for queues, but arrays are supposed to be more simple). I have tried including a priming read before the main for loop because I thought this issue was an off by one issue. This didn't fix the issue. For example here's what the data would look like:
1st run :
A
B
C
D
2nd run :
E
A
B
C
D
I have included my code and if you all see something that I can do to fix this, please let me know.
Thank you for your time,
Seth
Solved! Go to Solution.
10-24-2011 02:38 PM
My guess is the race condition you have created by using local variables.
You have local variables of min array, mean array, max array, cycle count, and channel names that you are using to write to a file. However the terminals are readily available that you could branch wires directly from
The problem is the race condition. Your local variables will be read very early in the iteration of the For Loop, before any valid data has been written to the terminals that those locals refer to.
Don't use local variables, just use wires.
10-31-2011 01:39 PM
Thanks!
That fixed it. So when is it appropriate to use local variables? I looked at some of the tutorials on them, but they didn't really specify. Are these just things that should be avoided?
10-31-2011 02:47 PM
If you can use a wire, use that instead of a local variable.
If you don't care about the order that value is written or read, then a local variable is okay. For example. If you are using a boolean to pass a stop condition that is determined in one loop (and written to a local variable), then you can read from that local variable in other loops to stop them.
As long as you completely understand how they work and the read vs. write, and how that can affect your program, then it can be okay to use them. If you don't understand and use them in the wrong circumstances, then they'll bite you as they did in this situation.