I am trying to understand timed loops. I provided an example of making a timed loop using a wait outside of the loop. However, I can easily rewrite it with your suggestion of a wait inside as this is a little cleaner. These succeed with no hang.
Basically, I do not understand how the timed loop causes the subroutine to fail. It is likely a race condition of some sort but I assumed that I could force LV to be serial processed and avoid a race condition. It appears that the while loop that drives the event structure never gets triggered when using the timed loop calling the subVI but works great either called directly (as standalone VI) or called inside of a fixed loop.
Before finding this "bug" (I think), the original idea was to have a subVI that could either be run directly or called by another program. The subVI would have a number of events that are triggered by buttons on the front. However, if called by another VI, you can have a group of buttons triggered by the calling program, one group at a time. For example, the initialize call would press buttons 1,2, &3 whereas a read call may press buttons 3,4,& 5. Alternatively, the user could mimic these calls by pressing the buttons directly in the VI.
I did this by having each button as an event inside a while loop but to return to the calling program. If run as a subVI, you need to terminate the while loop to return. Thus, the independent routine that "pushes" the buttons toggles a stop flag to terminate the while loop containing the events. However, to avoid race conditions, I need to make sure that the while loop driving the event is initialized before pushing the buttons. Thus, the setting a flag inside the while loop and the parallel routine waiting for that flag. Now, I understand that you could program each event as another subVI and that process may be preferable. However, this idea should work and has an advantage of all the routines being in one subVI and allowing a user to test each button independent of the calling program. Why, because I am building both the hardware, drivers, and high-level program at the same time in a complex system and need to see how they interact.