09-05-2006 01:13 PM
09-05-2006 01:42 PM - edited 09-05-2006 01:42 PM
Message Edited by kehander on 09-05-2006 01:44 PM
09-05-2006 02:06 PM
09-05-2006 02:14 PM
With the caveat that I don't know exactly what you are trying to do ...
I think you need to get rid of allllllll the local variables. Bad bad. I had to experiment because I've never used them. Here is a custom control and a VI that uses them. Is this along the lines of what you are trying to do? I'm not going to explain unless it is. Two concepts you (probably) need to learn:
09-05-2006 02:21 PM
Hi Ron,
I think kehander was correct in calling this a race condition.
In this thread we talk extensively about how evil globals are and you will find many of the issues with globals are shared by locals.
http://forums.ni.com/ni/board/message?board.id=BreakPoint&message.id=2362&jump=true
The race condition in your code happens when the state of the cluster is read as shown here
Then the cluster value is read again here
which gives them both a copy of the "before" data.
THEN you do the bundle and write the results to the indicator.
MEANWHILE the other code does a bundle using the "before" data and writes the modified cluster over-top of the data that was written by the first writter of the local.
If you read the posting by Roberto ( a C programer) you will see that this issue is not just a LV issue.
The issue boils down to "TWO Writters".
How to avoid this?
The hard way:
You can create a semaphore that must be acquired before writting or reading and then you various code snippets use this flag to controll access to the control. I have only had to resort to this approach once (let's not go there).
THe easy way:
Use a LV2 global! See the LAVAL FAQ here for more background info.
http://forums.lavag.org/index.php?showtopic=273
In a LV2 the data is stored in a shift register inside a sub-VI. Since only one VI can call a sub-VI at the same time (Re-entrant VI will not work here) the code that modifies your data structure is protected from race conditions.
I hope that helps,
Ben
09-05-2006 02:24 PM
@Rhayes wrote:
If I place a probe on the local that is changed and one on the cluster itself I notice that the cluster isn't always updated.
You cannot place a probe on a local variable or on an indicator terminal. Probes are always on wires. The wire receives only new data whenever it gets serviced by dataflow while a terminal can also get updated if one of the local varables receives new data. This will then not be reflected on a probe on the wire leading to the terminal. And vice versa...
What exactly are you doing?
09-05-2006 02:42 PM
09-06-2006 01:26 PM
09-06-2006 01:28 PM
HI Ron,
Could you please post a small set of VI's that demonstrates the problem you are having now?
Trying to help,
Ben
09-06-2006 01:43 PM - edited 09-06-2006 01:43 PM
Message Edited by Rhayes on 09-06-2006 01:50 PM