LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can this unbundle/bundle possibly lead to a race condition related problem?

Solved!
Go to solution

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.)

 

 referenceRace.png


GCentral
0 Kudos
Message 1 of 5
(2,781 Views)

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

 

0 Kudos
Message 2 of 5
(2,758 Views)

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. 


GCentral
0 Kudos
Message 3 of 5
(2,751 Views)
Solution
Accepted by topic author cbutcher

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

Message 4 of 5
(2,740 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 5
(2,732 Views)