Using WaitForMultipleObjects every second...

Posted on 2003-03-04
Medium Priority
Last Modified: 2012-08-14
Morning all,
Just wondering if anyone can help with this.
I'm writing an app that involves the user being able to start variuos commands, each of which starts a new thread. So i have an array of threads. Then every second i call WaitForMultipleObjects(num_threads, thread_handles_arr, FALSE, 0) and analyse the return value. (I dont wait on each thread to finish using INFINITE because the system needs to be usable all the time and not hanging on one thread).
This is fine for just one thread, but with more than one, it returns zero (WAIT_OBJECT_0) when the 0th element has become signalled, and from each second onwards just returns "ERROR_INVALID_HANDLE". Even though some of the other handles higher in the array havent become signalled.
Is it true that ERROR_INVALID_HANDLE is returned if at least one of the handles in the array is invalid ? Or am i imagining that ? I know that WaitForMultipleObjects returns the lowest element in the array that's become signalled, but what about the after that ?

Question by:NT1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 45

Accepted Solution

Kent Olsen earned 75 total points
ID: 8064032

After WaitForMultipleObjects() returns a signalled thread, (indicating that it has finished), you are going to have to remove it from the list.

The function scans each item in the list (array) and returns a value to you when the handle becomes invalid (the thread has issued a "finished" signal).  If you don't clean up the list, the next call effectively instructs the function to wait on an invalid handle.  This is what you're seeing.



Author Comment

ID: 8064115
Yeah, i see that now, thanks.
Damn Windows..
LVL 45

Expert Comment

by:Kent Olsen
ID: 8064151

Nice sig.   ;)

-- If you don't have fences, you don't need Gates.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question