From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

Shutdown race condition with main VI launching a root actor

I have the following situation: my main VI initializes an actor, and launches it as the root actor. The actor has opened some queue references during initialization, before launch. The queues are used for cleanup, which is called by actor's Stop Core.

To stop execution, I have my main VI send a Stop message to the root actor, and the VI stops. However I see errors 1 during cleanup when using actor's queue. It seems to be a race condition: the actor's queue references become invalid before Stop core executes, making the cleanup function fail. I assume it's because the main VI owns the queue references, and when it stops it makes them invalid.

Is my understanding correct?

How can I solve it, without making an awkward notification mechanism so that the main VI waits for actor shutdown?

I use LV2014.

0 Kudos
Message 1 of 6
(4,100 Views)

CharlesB64 schrieb:

To stop execution, I have my main VI send a Stop message to the root actor, and the VI stops. However I see errors 1 during cleanup when using actor's queue. It seems to be a race condition: the actor's queue references become invalid before Stop core executes, making the cleanup function fail. I assume it's because the main VI owns the queue references, and when it stops it makes them invalid.

On invoking an Actor, it creates its own queue (the Actor enqueuer being returned by the launch VI). This particular queue is valid as long as the Actor is alive. On sendig a Stop message to the Actor, it terminates and destroys its enqueuer. This means that after having send the stop message you basically should not use the Actors enqueuer anymore.

In my opinion, the Stopping mechanism in the AF is designed bullet proof as long as you don't mess up the routines on your own.

Hope I haven't misunderstood your question. If so, pleas post a screen shoot to better describe the issue

0 Kudos
Message 2 of 6
(3,475 Views)

I'm not talking about the actor's enqueuer, but my own queues that I create during object initialization, and that should still be available during actor's Stop core.

0 Kudos
Message 3 of 6
(3,475 Views)

Sorry, seems I didn't get this bit.....

So you are obtaining those queues in PreLaunch Init.vi, right? And you are saving those Q refs in the Actors private data using a bundle or an In Place?

0 Kudos
Message 4 of 6
(3,475 Views)

I initialize them in a separate VI called before launching the actor, not in Pre launch init. Maybe that's what I should do to solve the problem

0 Kudos
Message 5 of 6
(3,475 Views)

Pre Launch Init.vi is usually the place to initialize things. You could as well perform some initialization in your Actors' implementation of Actor Core.vi before calling the parents' implementation.

The important thing is that you have to make sure, the Q refs are neatly stored in the Actors' private data, from where it ia accessible.

0 Kudos
Message 6 of 6
(3,475 Views)