From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Acquiring resources requiring Cleaning (Pre-Launch-Init vs Actor Core)

Solved!
Go to solution

This is sort-of a follow-on to the discussion here:

2013 AF Post

 

The question at hand is where to acquire some resource that requires cleanup code.  It seems to me that this can't really be done in Pre-launch init.  This is because even if the object's pre-launch succeeds, if a parent/child's subsequent pre-launch fails, then we will not have an opportunity to clean up (because Stop core will never run, and our own pre-launch ran without errors)

 

Resource acquisition in Actor core can be problematic, (but possibly the only option) because the child Actor cores will already be running.  So if initialization isn't done in pre-launch, then the children can't assume the resource has been acquired. To make this work I might have to add a flag the children check to know when init has occurred.

 

In c++ the constructor would be the right place.  And while it is true that if a given constructor throws the destructor isn't called (as was pointed out in the old thread); c++ doesn't have the problem above because if a constructor completes as part of a inherited object's construction, then its destructor will always be called (http://www.gotw.ca/publications/mill13.htm)

 

Since the discussion in that old thread is rather dated I figured that I would check to see if people had any new/additional thoughts.

0 Kudos
Message 1 of 4
(3,236 Views)
Solution
Accepted by AdamZeroK

It might not directly tie onto your concern, but one potential solution regarding children not having access to parents' resources acquired in Actor Core would be to only use those resources via messages - messages aren't handled until you've reached the top of the Actor Core chain, by which point all of the Call Parent Nodes have to have been reached. This can mean so long as acquisition occurs before you call the parent node, you know everything is acquired before answering your first message.

 

It's of course not great, because frequently you might want some synchronous code during the pre-Call Parent Node section of Actor Core, which is less simple via messaging than just a subVI...

 

In terms of handling failing Pre-Launch Inits at different levels, I think you could create your own dynamic dispatch VI "Clear Initialization Resources.vi" or similar, and call it in an error case in PLI. Enforce calling parent nodes, and you'll get it called for every level regardless of which throws the error (from the lowest up). Here your problem might be trying to clean up resources you didn't acquire, e.g. with Actors A > B > C(hild), where all acquire resources in PLI, if C acquires, B errors, then calls the clean-up VI, C will release, B will release (perhaps partially) then A will try to release but not have acquired. YMMV.


GCentral
Message 2 of 4
(3,190 Views)

Similar to what Chris wrote:

 

if this initialization error occurs in PLI, handle it there.

 

In theory, there is also the possibility to use the Last Ack Message to do some handling in the caller, yet I think this not as straight-forward and clear as one would like it to be.

0 Kudos
Message 3 of 4
(3,184 Views)

Yes I think this more-or-less works as a solution.   Could be a bit ugly to implement, but it should work.

0 Kudos
Message 4 of 4
(3,135 Views)