Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WaitForMultipleObjects is not waiting

Status
Not open for further replies.

Wendyj2

Instructor
Nov 5, 2004
8
CA
I am running several programs with CreateProcess and want a "batch" of them to run by group number before the next batch starts. I am trying to use WaitForMultipleObjects to do this. I have created a vector to hold the handles returned. Once the batch has all started processing, I then make a dynamic array using the information in the vector. I am trying to use this dynamic array as the second parameter in WaitForMultipleObjects. When I GetLastError(), error 6 comes up which means (I believe) that I have invalid handles in the array. The program compiles and runs, but the WaitForMultipleObjects does not work.

I can post the code if this will help
 
Dumb question: have you tried using WaitForSingleObject on the individual handles?

Good Luck,

Greg
 
I am required to have all the programs in a certain group launch together, wait until they all come back and then lauch the next group concurrently. I don't know how I could do this with WaitForSingleObject since WaitForSingleObject actually seems to make everything wait for each process to complete indivdually.

I think I have it running now except for the last batch run. All the rest seem to do fine, except the last one.

This is a school assignment and I think I have spend 50 - 60 hours on this. Am kind of at my wits end.

Thanks for your input however.
 
Check that the program has been built as multi-threaded.
 
Wendy, I think Greg was suggesting that you make your batches a single job, just to ensure that all the handles were indeed valid.
 
I really don't understand what you mean. The text doc I have no control over, it is just a commandline feed into the program. I am required to use the WaitForMultipleObjects for this assignment. I do have it working somewhat now, I have valid handles etc. I am now at the point where my logic is flawed and I don't know how to sort that out (too close to it I think):

This is how I have it running:

read in the file from command prompt into a vector of classes that holds 3 variables: grouplaunch number, program to run, any parameters needed

for loop to scroll through all the information in the vector

if (launchgroup == currentgroup)
and put these into a new vector2

else
iterate through vector2 and run createprocess with each and capture handle info
WaitForMulitpleObjects
get the timing and exit information
put all program, timing and exit information into vector3
change the currentgroup to the new group number
decriment (i) (I know this is evil)

if(i is the last program to run)
(I had to add this because I had to capture the last program for it would never hit the else statement)
Everything in the else statement is put into here again

At the end, vector3 is printed to screen in a table format.

I know it is pretty bad and clunky and I shouldn't have the same code twice(I will fix that later on), but right now it at least works for the most part. I think I need more help now with the logic than anything else.

Thanks for the input though, it makes me think from different angles.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top