Mike Le Posted April 20, 2013 Report Share Posted April 20, 2013 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. Quote Link to comment
Aristos Queue Posted April 20, 2013 Report Share Posted April 20, 2013 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. Quote Link to comment
Mike Le Posted April 22, 2013 Author Report Share Posted April 22, 2013 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? Quote Link to comment
drjdpowell Posted April 22, 2013 Report Share Posted April 22, 2013 Is the expected behavior in this case that the reference would persist for the lifetime of the launched actor? Yes. It shouldn’t matter how deep in the call chain the reference is created. BTW, what is the semaphore for? 1 Quote Link to comment
Aristos Queue Posted April 23, 2013 Report Share Posted April 23, 2013 What drjdpowell said. Quote Link to comment
OlivierL Posted April 25, 2013 Report Share Posted April 25, 2013 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. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.