03-06-2017 04:23 AM
Question is as in the title - I'm ignoring the error from the Close Reference (and not checking the reference exists) since I gather that does nothing useful (assuming a case structure and Is A Refnum test) but I'm wondering if it's possible that since execution order isn't enforced here, I could possibly write the new reference first, and then close the old reference (I realize a different reference is passed into the CS, but I don't know how Close Reference works - perhaps it closes based on a memory location etc.)
Solved! Go to Solution.
03-06-2017 05:17 AM - edited 03-06-2017 05:19 AM
Hi cbutcher,
i dont think you will get a race condition in this case since the read/write operation order is enforced by dafaflow.
The read operation is finished when the case structure executes, so write will come after read.
Without the case structure you might run into Problems.
Edit: Just realized, even without the case structure there's no problem at all.
The cluster with the updated Reference never runs into the unbundle&close part of your code.
Sq
03-06-2017 05:31 AM
That was what I thought - I was just concerned that, for example, closing a reference might be interpreted as something like
Go to memory location A. Lookup the value of the VI being held there. Run stop/abort and then write a Not-A-Refnum constant over the memory location.
in which case I can imagine a potential to shoot myself in the foot.
03-06-2017 05:49 AM
As far as i understand it, and i hope someone corrects me if i'm wrong, references are not pointers to a memory location but merely another numerical value that LabVIEW throws around.
A quick test reveals that the reference stays in the cluster without being changed.
Can't upload code from work, but if you can do it in under a minute so you can see for yourself.
Just open a ref to a VI, typecast it to I32, bundle the ref into a cluster, close it and then read it out again. Values should be equal.
Sq
03-06-2017 06:15 AM
From what has been explained to me by a non-compiler person inside of R&D, the compiler is smart enough that for any wire branches it will to do any possible read operations on the wire before doing any writes. The reason is to avoid memory allocations. Regardless, dataflow ensures that you will not close the wrong reference. And if you do find that it closes the wrong reference, report it immediately because that would be a MAJOR bug.