LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Semaphore problem upon reinitializing VI

And why/where exactly do I want to destroy the semaphore. Because I need it as long as my program is running... so I don't see a reason to destroy it... cause I have to initialize a new one then...
0 Kudos
Message 11 of 16
(1,345 Views)

kristofparedis wrote:
And why/where exactly do I want to destroy the semaphore. Because I need it as long as my program is running... so I don't see a reason to destroy it... cause I have to initialize a new one then...

Thats kind of like leaving the front door open when you come home because you "intend to go to work again tomarrow anyway."  Open-close it,  Create it-destroy it, are good code practices and help your code be more self-contained.  You don't allways want to rely on an OS garbage collection to clean up for you.


"Should be" isn't "Is" -Jay
Message 12 of 16
(1,344 Views)

ok, makes sense.

 

Thanks Jeff. 

 

Now concerning my initial question. Say that I do need to work with a local for my reference. Is there any way to work around the issue, e.g. is there a way to switch off the reinitialization for the locals, or to put the correct value back in (by recreating a new semaphore), so that my program can continue? Because I guess that the value of the local gets deleted and the acquire function gives an error because it can't read the local any more... right?

 

Kristof

0 Kudos
Message 13 of 16
(1,342 Views)

kristofparedis wrote:

ok, makes sense.

 

Thanks Jeff. 


 

Because I guess that the value of the local gets deleted and the acquire function gives an error because it can't read the local any more... right?

 Correct

Kristof


 

 

Now concerning my initial question. Say that I do need to work with a local for my reference.

You NEVER have to work with a local variable (OK I have used them but, very rarely)

 

there is a community nugget on FG's and AEs that  Ben wrote.  It will give you an idea how you can store that semaphore in a sub-vi and access it from anywhere.  Wires would be the "prefered" method of passing the referance to the data though.


"Should be" isn't "Is" -Jay
0 Kudos
Message 14 of 16
(1,333 Views)

Thank you,

 

One more thing on your last comment: you never have to use locals and then I consider my case solved 🙂

I was trying to see whether I could get rid of all my locals in my program, but say I have 3 for loops in a sequence, each generating a certain amount of data, one after the other. In my current program, I write everything I collect into a local and with a seperate while loop I pick-up the data and plot them continuously. How do you managae this without a local (since the for loop only passes it data to the next when it is finished). So i can basically only plot in 3 steps all the data from one loop at a time, instead of point by point.

 

Kristof

0 Kudos
Message 15 of 16
(1,326 Views)
Check out queues and Producer consumer loops.  Much faster!  however you can pass the data out of a loop in a FG.

"Should be" isn't "Is" -Jay
0 Kudos
Message 16 of 16
(1,305 Views)