Jump to content

Question about using Semaphores with Actors


Recommended Posts

Hey guys,

 

I'm trying to figure out how to keep a semaphore reference persistent in memory so it doesn't get destroyed.

 

At first I had the semaphore reference inside the Actor's private data and that was fine. I could throw the reference into the Actor data and retrieve it at will, no problems. It was never destroyed as long as the Actor was running.

 

Today I moved the semaphore reference into a File IO class and dropped an instance of File IO into the Actor private data. This led to immediate problems when I tried to re-run my code; the reference would get destroyed and I would get 1111 errors. I tried Obtaining the reference directly in one of the Actor methods and then feeding it into the File IO object via an accessor method, but this didn't improve the result.

 

I'd like to have the semaphore in the File IO class; that's where it makes the most sense to have it. That way restricting and releasing access to my data file is handled entirely in the File IO class. But the semaphore reference drops out of memory if it's not directly in the Actor private data (rather than bundled in an object that is then stored into the Actor data).

 

Any suggestions? I haven't used semaphores extensively, so if I'm misunderstanding the root problem, clarification would of course be greatly appreciated.

Link to comment

All references have the same lifetime as the top-level VI that created them. Each actor is a separate top-level VI. You can have the reference inside the FIle IO class as long as the File IO object is initialzied inside the Actor Core.vi or Prelaunch Init.vi. That will give the lifetime of the reference the same lifetime as the launched actor.

 

There's nothing special about semaphores in all of this.

Link to comment

Thanks, AQ. The File IO object IS initialized inside Actor Core.vi, but not on the top-level block diagram of Actor Core. It's initialized in a method "Initialize Config File.vi," which is run before the Actor Core's Call Parent Method node.

 

Is the expected behavior in this case that the reference would persist for the lifetime of the launched actor? Or do I need to move the initialization onto the top-level block diagram of the Actor Core override?

Link to comment

Mike,

 

I had a very similar issue this week.  In my case, I had a semaphore that was created in a VI (let's call it ) and I was saving that reference in a shift register for future calls.  Everything worked fine at first but every now and then, I had error 1111.  After investigation, I found out that the VI might be first called from within a different thread and the reference was lot when the thread finished.  That separate thread was a different GUI, running in parallel with the main application, launched with the "Run VI" "Invoke Node". In the "normal case", as long as that VI was first called from within the thread of the main application, the reference stayed in memory until the application completed.

 

To solve my problem, I created the named semaphore in the main application during my Init state.  I hope that this help.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.