Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

Using WaitForMultipleObjects every second...

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 ?

Thanks...
0
NT1
Asked:
NT1
  • 2
1 Solution
 
Kent OlsenData Warehouse Architect / DBACommented:

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.


Kdo

0
 
NT1Author Commented:
Yeah, i see that now, thanks.
Damn Windows..
0
 
Kent OlsenData Warehouse Architect / DBACommented:

Nice sig.   ;)

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

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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now