LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Race condition while removing and inerting a VI into a subpanel

Once more I need some help with a tricky situation...

 

I'm trying to move a FP of a VI from one subpanel to another.

 

That's how far I am:

Consider two VIs running independently as main instance, both with a subpanel on the FP. The first VI - the source - has inserted a VI (SP-VI in the following text) in its subpanel, the second - the target - not. Now the target sends a stop command via user event to the source. The source removes the SP-VI from its subpanel, then destroys the user event reference and stops. In parallel the target polls the user event reference and delays until the reference becomes invalid. After that happened, it trys to insert the SP-VI.

 

The insert fails.

If I add an additional wait between the invalid reference check and the insert VI it works.

 

Seems the subpanel needs some time to remove the inserted VI and because of that I'm running into a race condition.

 

What are Your reccommendations to determine if a VI's frontpanel is available to insert into a SubPanel?

Should I simply retry on an error? I'm not sure if its a good practice to try until the insetion succeeds.

0 Kudos
Message 1 of 3
(2,309 Views)

I don't really have experience with moving a VI between subpanels, but retrying something that has the potential to fail and then succeed certainly sounds reasonable. You should probably make sure you do have some kind of timeout, so that if the insert really doesn't succeed, you break. This can be done with a while loop or with a for loop with a conditional terminal.


___________________
Try to take over the world!
0 Kudos
Message 2 of 3
(2,284 Views)

I normally just insert the new VI over the top of the other one i.e. I just call Insert VI with a different VI reference. I can't say I've ever had/noticed any problems with race conditions when doing it that way. Obviously you need to remember to do something about the reference so it gets closed but that doesn't really apply in my situation as I handle the VI references elsewhere.

 

That'll serve me right for not reading properly. There is a method you can use to determine if the VI is in a subpanel by reading/writing the "FP.Resizeable" property and if it returns error 1442 (or something? I don't remember the exact code) then the VI is in a subpanel. You could retry that and only insert it into the other panel if it doesn't think it's in a subpanel.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 3 of 3
(2,276 Views)