09-15-2020 07:51 AM - edited 09-15-2020 08:12 AM
Dear all!
While trying to decouple a module from a host program, I have encountered an unexpected behaviour that invalidated Event and Queue refrerences inside a Functional Gloval Variable (FGV, Action Engine, ...). I would be grateful for any comments on this - I suspect that there may be an easier solution for what I am trying to do, which would also be good to know.
I have attached three files, representing three components:
The Guest is executed in reentrant mode. This adds comfort during development by allowing me to keep the front panel open and enables the simultaneus use of more than one instance of the module.
Now, the issue: When the FGV is initialized from the Host, the FGV creates references to an event and a queue and saves these refrences. I would now expect these references to stay valid during the lifetime of the FGV. When the FGV enters its polling mode, called from within the Guest, the references indeed stay valid (as indicated by "NotARefNum?"-Tests). When the Host VI is closed, I would expect these refnums to remain valid. They have been created inside the FGV, after all.
However, after stopping the main VI, the references to the Event and Queue created by the call from the Host stop being valid, but the references created from the call by the Guest remain valid.
Tested on: LabVIEW 2016, 32bit, Win10
I believe that this is unexpected behaviour. Is there an alternative way or best practice to achieve what I am trying to do, which is passing events to decoupled submodules and detecting unexpected shutdowns?
Best Regards,
Leopold
Solved! Go to Solution.
09-15-2020 08:22 AM
Nope, this is totally expected. It has been discussed many times in this forum. The heart of your issue is that the references are tied to the process/VI that created it. Since you created the queue in the host, the queue is tied to the host VI. So when the host VI closes (ie leaves memory), all of the references tied to it are also closed, making them invalid for other VIs/processes. My rule of thumb is a queue should be created and maintained by its consumer.
09-15-2020 08:34 AM
@LLindenbauer wrote:
Is there an alternative way or best practice to achieve what I am trying to do, which is passing events to decoupled submodules and detecting unexpected shutdowns?
Create the references in the host, pass reference values to the guests... If the guests create references, pass them over a reference (queue, user event, DVR, control reference) created by the host.
References live in the top level VI's data space of the VI that created the reference. This can be unexpected the first ~5 times you run into it, but it is documented and by design. Note that the VI that created the reference might not have stopped running! The VI can be used in more than one hierarchy. Each hierarchy will have it's own top level data space that keeps the references created in it.
09-15-2020 09:12 AM
Thank You both! That explains what went wrong.
wiebe@CARYA wrote:
[...] it is documented and by design.
@crossrulz wrote:
It has been discussed many times in this forum.
I have tried to look for documentation before. In light of this new information, Point (8) in https://zone.ni.com/reference/en-XX/help/371361R-01/lvhowto/creating_user_events/ seems to come close to this behaviour. Do You have a link to the documents?
Best,
L
09-15-2020 09:29 AM
@LLindenbauer wrote:
Thank You both! That explains what went wrong.
wiebe@CARYA wrote:
[...] it is documented and by design.
@crossrulz wrote:
It has been discussed many times in this forum.
I have tried to look for documentation before. In light of this new information, Point (8) in https://zone.ni.com/reference/en-XX/help/371361R-01/lvhowto/creating_user_events/ seems to come close to this behaviour. Do You have a link to the documents?
Good point.
Haven't found any documentation yet... Guess an online knowledgebase or forum post is as good as it gets.
It might be "common" knowledge, that is simply a black corner in the official documentation...