06-11-2015 05:23 AM
I'm developing a series of projects that are based on the Actor Framework and my actor dependency hierarchy is starting to get some depth. One of the issues I'm facing now is making sure that each actor will only stop running (and signal this via a Last Ack to a higher-level actor or via a notification to non-AF code that launches it) once all of its nested actors have stopped running.
For instance, say I have a type of actor that handles communication with a microcontroller over USB - a USB Controller Actor. I might want to have an application-specific actor that launches USB Controller Actor to issue commands to the microcontroller. When shutting down, I want this top-level actor to send a Stop Msg to USB Controller Actor and then wait to receive a Last Ack back before sending a notification within a provided notifier to the non-AF application code, which can then finish shutting down completely.
I'm sure that having actors wait for all nested actors to shutdown before shutting down themselves is an extremely common requirement and I'm confident National Instruments have made it possible to handle that in a simple, elegant manner. I'm just struggling to figure out what that is.
The approaches I've experimented with are:
The figures below show how I implemented the second approach. Ignore the broken object wires - they only appear that way in the snippets.
Figure 1 - Stop Core.vi from the second approach
Figure 2 - Handle Last Ack Core.vi from the second approach
06-11-2015 06:43 AM - edited 06-11-2015 06:43 AM
The best place for these types of discussions is the AF group in the communities section of this site. You will also find some existing discussions on this topic there, including a fairly recent one (last couple of months) which went into this in some depth. I haven't read it too closely, but I think the bottom line was a reluctance to have something like this built-in for all actors, because the desired behavior is actor specific. There may have been some talk about adding some components to make it easier to do this and if that's the case, there may also be a branch which has this which you can check out of Github. Look at the group.
06-11-2015 07:06 AM
@tst wrote:
The best place for these types of discussions is the AF group in the communities section of this site. You will also find some existing discussions on this topic there, including a fairly recent one (last couple of months) which went into this in some depth. I haven't read it too closely, but I think the bottom line was a reluctance to have something like this built-in for all actors, because the desired behavior is actor specific. There may have been some talk about adding some components to make it easier to do this and if that's the case, there may also be a branch which has this which you can check out of Github. Look at the group.
Thanks, I've cross-posted it over there. I'll also search to see if I can find similar discussions.
> I haven't read it too closely, but I think the bottom line was a reluctance to have something like this built-in for all actors, because the desired behavior is actor specific.
That seems kind of odd. I don't have an expert grasp on Actor Framework yet, but my understanding is that you override Stop Core.vi to implement actor-specific deinitialisation logic. After that's executed, the framework will automatically send a Last Ack to the parent actor.
If that's correct, then surely all the actor-specific deinitialisation logic can be placed into the overridden Stop Core.vi and you could update the design of the framework to allow a parent actor to only stop running after it's received a Last Ack message from each nested actor? Since the parent actor would only need to wait on each Last Ack without caring what actual deinitialisation is required by the nested actors, it'd make this solution extremely general and reusable. Hopefully I'll come across one of these discussions which will clarify the limitations of this approach for me.
06-11-2015 07:16 AM - edited 06-11-2015 07:17 AM
It wasn't that hard to find - https://decibel.ni.com/content/thread/27138?tstart=0
But with dozens of posts, I have no intention of rereading it now.
Also, when crossposting, it's considered polite to add a link, so that people can see if the other thread has relevant replies.
06-11-2015 07:46 AM - edited 06-11-2015 07:48 AM
@tst wrote:
It wasn't that hard to find - https://decibel.ni.com/content/thread/27138?tstart=0
But with dozens of posts, I have no intention of rereading it now.
Also, when crossposting, it's considered polite to add a link, so that people can see if the other thread has relevant replies.
Thanks. I've only read the first page for now but I find this interesting (I'm not sure how to format non-reply quotes, sorry):
@ "AristosQueue wrote:
@CaseyLamers1 wrote:
I think that this would be a nice addition. I think how a program stops is just as important as how it starts.
I think everyone who has worked on AF design agrees with this. Indeed, managing "Stop" was *the* thing that lead to the creation of the Actor Framework in the first place. The other issues (deadlock/hang avoidance and resource management) were secondary to just trying to get a clean shutdown.
@CaseyLamers1 wrote:
...
I find the current code a bit lacking....
My concern would be that the mixing of a verified stop and a regular stop could create confusion and lead to people having trouble during editting and testing with the project ending up locked (due to VIs left running which did not shutting down).
Your concern is to some degree why no verified Stop exists in the AF already. We looked at each actor as an independent entity, and left it open to the programmer to add an additional managment layer for those applications that needed it. But over time, I have seen that particular management layer come up more often, which is why I am exploring the option."
So that gives one of the reasons why this hasn't already been implemented but also points out that it's something quite a lot of people want.
> Also, when crossposting, it's considered polite to add a link, so that people can see if the other thread has relevant replies.
Noted. Here's the discussion: https://decibel.ni.com/content/message/104983#104983
Edit: since there doesn't seem to be any NI-provided way of doing this yet, I suppose I'll try rolling my own at some point. The ideas posted in the discussion you linked seem pretty useful.