How to code a parallel 'for loop' and 'while loop' where the while loop cannot terminate until the for loop has finished?? (queues also present)

I've attached a sample VI that I just cannot figure out how to get working the way that I want.  I've labeled the some sections with black-on-yellow text boxes for clarity during the description that follows in the next few sentences.  Here's what I want:
1) overall -- i'm intend for this to be a subVI that will do data acquisition and write the data to a file.  I want it to use a producer/consumer approach.  The producer construct is the 'parallel for loop' that runs an exact number of times depending on user input (which will come from the mainVI that is not included).  For now I've wired a 1-D array w/ 2 elements as a test case.  During the producer loop, the data is acquired and put into a queue to be delt with in the consumer loop (for now, i just add a random number to the queue).
2) the consumer construct is the 'parallel while loop'.  It will dequeue elements and write them to a file.  I want this to keep running continuously and parallel until two conditions are met.
      i. the for loop has finished execution
      ii. the queue is empty.
   when the conditions are met, the while loop will exit, close the queue, and the subVI will finish. (and return stuff to mainVI that i can deal with on my own)
Here's the problems.
1)  in the "parallel for loop" I have a flat sequence structure.. I haven't had time to incorporate some data dependency into these two sequential sections, but basically, I just care that the "inner while loop" condition is met before the data is collected and queued.  I think I can do this on my own, but if you have suggestions, I'm interested.
2)  I can easily get the outer for and while loops to run sequentially, but I want them to run in parallel.  My reasoning for this is that that I anticipate the two tasks taking very different amounts of time. .. basically, I want the while loop to just keep polling the queue to get everything out of it (or I suppose I could somehow use notifiers - suggestions welcome)...  the thing is, this loop will probably run faster than the for loop, so just checking to see that the queue is empty will not work... I need to meet the additional condition that nothing else will be placed in the queue - and this condition is met when the for loop is complete. basically, I just can't figure out how to do this.
3) for now, I've placed a simple stop button in the 'parallel while loop', but I must be missing something fundamental here, because the stop button is totally unresponsive.  i.e. - when I press it, it stays depressed, and nothing happens.
suggestions are totally welcome!
thanks,
-Z
Attachments:
daq01v1.vi ‏59 KB

I'd actually like to add a little more, since I thought about it a bit and I'm still not quite certain I understand the sequence of events...
altenbach wrote:
zskillz wrote:
So i read a bit more about the 'dequeue element' function, and as I understand it, since there is no timeout wired to the dequeue element function, it will wait forever, thus the race condition I suggested above can never happen!
Yes, you got it!
As I've thought about it a bit more, there's a few things that surprise me... first, the reason the 'dequeue element while loop' errors is not because there's nothing in the queue, it's becaues the queue has been released and it's trying to access that released queue...   However the problem I have is this --- Even though there's no timeout wired to the dequeue element, I still would think that the while loop that contains it would continue to run at whatever pace it wanted -- and as i said before.. most of the time, it would find that there is nothing to dequeue, but once in a while, something is there.  however, it seems that this loop only runs when something has been enqueued.  the reason I say this is illustrated in the next code sample MODv2 that's attached below.  I've added a stop button to the "queue size while loop" so the program runs until that is pressed.  I've also added a simple conditional in the "dequeue while loop"  that generates a random number if it a button is pressed... but this button is totally non-responsive... which means to me that the "dequeue while loop" isn't actually continuously running, but only when an element is added to the queue.  this still seems almost like the 'dequeue while loop" waits for a notifier from the queue telling it to run.  can you explain this to me? because it is different from what I expect to be happening.
rasputin wrote:
I tried to open your VIs but it doesn't work. LV
is launched, the dialog box (new, open, configure...) opens and then...
nothing. Not even an error message. I guess it isn't a problem of LV
version or a dialog box would appear saying this. Could you, please,
send a image of the code?
Thanks,
Hi Rasputin, I'm using LV8.  I assume that was your problem, but who knows.  I've attached a pic of of altenbach's solution since it's what I needed.
thanks
-Z
Message Edited by zskillz on 10-20-2006 11:49 AM
Attachments:
daq01v1MODv2.vi ‏63 KB
daq01v1MODpic.JPG ‏116 KB

Similar Messages

Maybe you are looking for

  • ACS 5.4 How to change CLI password?

    Anyone know how to change the ACS 5.4 CLI password? I found the command "acs reset-password".  But it seems to reset the GUI password instead of CLI password. Thank you very much!

  • Classification in ADOBE Forms

    As far as my understanding : The usage of ADOBE Forms can be classifies as :- Kindly confirm whether the following are correct or not. 1. Print Forms: This type of usage involves in generation of reports, some confirmation pages and receipts. We can

  • Supplier ******* not intended for purch. org error in S Cart

    Hi - We have set up a Dev SRM system using Extended Classic Scenario When we create shopping carts and we try to assign a vendor we get message Supplier A111111 not intended for purch. org. The vendor exists in our ECC 6.0 system under purchase organ

  • How to extract the list of BOM materials through ABAP query?

    Hello Experts I want to extract a report from SAP which should contains the following, 1). Main Material with description 2). Sub material with description and quantity I have tried with the tables MAST, STKO AND STPO but i couldn't able to create th

  • Special effects problem. Can anyone help me?

    I have Adobe Premiere Elements 7 and I want to import media into the program from www.detonationfilms.com but when I look for the right effect I need and take it back to adobe premiere elements 7. The pop up says the file is not supported or you need