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: 

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
(5,645 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
(5,643 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 Employee 2012-2023
Message 3 of 31
(5,640 Views)

Well, they both stopped when I tested.

0 Kudos
Message 4 of 31
(5,624 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
(5,605 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
(5,591 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.

0 Kudos
Message 7 of 31
(5,576 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 Employee 2012-2023
0 Kudos
Message 8 of 31
(5,571 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 Employee 2012-2023
0 Kudos
Message 9 of 31
(5,568 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.

0 Kudos
Message 10 of 31
(5,563 Views)