LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can you closing a reference using a local variable to that reference?

Solved!
Go to solution

@JÞB wrote:

A Local (or Global) variable to a reference just sounds like a really bad idea.  If you really need to avoid the wire an Action Engine with Open / Get / Close methods sounds a whole lot safer and a darn sight easier to debug.


And...

 

Include a flag in the internal data stored in the AE that indicates if the refrence has been closed. If any operation requiring a valid references is attempted while the flag indicates the reference has been closed is is invalid, you can return a error message to the caller clearly spelling out why the invocation failed.

 

If I am going to write code that others will use, I try to write it such that it warns them when they are not playing by the rules with error messages.

 

Just my 2 cents,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 11 of 14
(680 Views)

Ben wrote:

Include a flag in the internal data stored in the AE that indicates if the refrence has been closed. If any operation requiring a valid references is attempted while the flag indicates the reference has been closed is is invalid, you can return a error message to the caller clearly spelling out why the invocation failed.


1. You will already get an error when you try to use the invalid reference.

2. What if somebody closes the reference outside of the AE?  Now your flag is invalid.

 

So I guess the point I am trying to make here is that your flag will work as long as the reference does not leave the Action Engine.  Otherwise, all bets are off.  And if you say that you can check to see if the reference is valid first, go talk to Fab and Mercer.  They actually found a race condition where a queue reference was closed between the checking for a valid reference and enqueuing an item (got error code 1).


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
0 Kudos
Message 12 of 14
(670 Views)

I aggree crosrulz about keeping the reference encapsulated in the AE.

 

There error message could be alittle more robust than the standard that will simply say the ref is invalid and could read as "You already closed the references!" or "The ref has nver been opened, make sure you open it first!"

 

The intent is to keep others from misusing the code I develop and let them quickly learn where and how the screwed up.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 13 of 14
(668 Views)

@Ben wrote:

I aggree crosrulz about keeping the reference encapsulated in the AE.

 

 

The intent is to keep others from misusing the code I develop and let them quickly learn where and how the screwed up.

 

Ben


Ideally, any action taken on the reference would be contained in a method of the AE (And, do  "Goto Nirvana" by wrapping the methods as a public API)  Thais keeps the follow-on developers honest.  Of course, some developer is going to grab their own ref to the object and write a nice bug.  You can laugh at them after they admit they did that and wasted a bunch of time tracking down their error.


"Should be" isn't "Is" -Jay
Message 14 of 14
(652 Views)