Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Stopping multiple helper loops with one user event

I'm trying to learn Actor Framework and how I should handle some actions in the actor core.


So the picture tells what I'm asking, is there some reason I shouldn't do as it is shown in the picture, stopping "multiple" loops with one event? Unregistering the event should probably be done after both loops have stopped, but is there something else completely wrong?

Waltteri_0-1612363163468.png

I saw this on some other post and know that it's not the way to do it:

Waltteri_1-1612363413723.png

Thanks.

0 Kudos
Message 1 of 31
(4,517 Views)

I think what you showed is fine. I usually tailor the helper loop's stop mechanism to the helper loop. For example, if my helper loop is an event handler, I'd stop it with a user event fired in Stop Core. If my helper loop is a queue or notifier, I'd destroy them in Stop Core and shut down the helper loop when the queue/notifier becomes invalid. If don't have queues/notifiers, and I don't want to deal with PITA User Events, I will just wire a Front Panel boolean to the stop terminal, and "push" the button by-reference in Stop Core.

0 Kudos
Message 2 of 31
(4,515 Views)

Only one of your helper loops will stop!

 

You need one register for events function per event structure: https://zone.ni.com/reference/en-XX/help/371361R-01/glang/register_events/

 

"When using dynamic registration, make sure you have a Register For Events function for each Event structure."

Craig H. | CLA CTA CLED | Applications Engineer | NI
Message 3 of 31
(4,512 Views)

Well, they both stopped when I tested.

0 Kudos
Message 4 of 31
(4,496 Views)

Craig's right. You need two too separate registrations. Only one of those loops should have gotten the event, unless you fired it twice.

 

That it worked? I have no idea why unless you fired it twice. It shouldn't have. One loop should have hung.

Sam Taggart
CLA, CPI, CTD, LabVIEW Champion
DQMH Trusted Advisor
Read about my thoughts on Software Development at sasworkshops.com/blog
GCentral
Message 5 of 31
(4,477 Views)

So this is the way to go?

Waltteri_0-1612369086265.png

 

No matter how many loops I added to the previous version, they all stopped.

I have Labview 2017 if that has anything to do with this.

0 Kudos
Message 6 of 31
(4,463 Views)

Yeah that's the way to go. I seem to have read somewhere that multiple event handlers per registration is "undefined" behavior. I think the message could get seen by both loops or it could be seen by only one, and it's not set which is which. I've tried to nail down the exact behavior for multiple loops with one registration but couldn't figure out a specific pattern.




Heads up! NI is moving LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 7 of 31
(4,448 Views)

The register for events function creates a queue of the input user events that are then de-queued by the event structures, so if you branch that wire to multiple event structures they race to de-queue the event, and only one of them can get it 🙂 (EDIT: see below for more clarification, they may both get it, but not always!)

Craig H. | CLA CTA CLED | Applications Engineer | NI
0 Kudos
Message 8 of 31
(4,443 Views)

You can also use the event inspector window to get a direct debug view of the events!

 

https://zone.ni.com/reference/en-XX/help/371361R-01/lvdialog/event_inspectorwindow/

Craig H. | CLA CTA CLED | Applications Engineer | NI
0 Kudos
Message 9 of 31
(4,440 Views)

@Craig_ wrote:

The register for events function creates a queue of the input user events that are then de-queued by the event structures, so if you branch that wire to multiple event structures they race to de-queue the event, and only one of them can get it 🙂


I know that's the "expected" behavior, but it does not work that way in practice.

 

For example:

 

events.png

 

 

 

Run that code, click "Send", observe that both Loop 1 and Loop 2 indicators sometimes change together, but not always. Hammer on the Send button and you will see the two numbers increment together, but sometimes one of them doesn't see the event.

 

BertMcMahan_0-1612371577499.png

 

Granted I'm a little low on sleep right now so I could've made a dumb not-enough-coffee mistake in my example code lol, but I've tried this once or twice before with "weird" results. You'd think it would act like a queue but it seems to duplicate some events.




Heads up! NI is moving LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 10 of 31
(4,435 Views)