In threads, WaitForMultipleObjects never returns if set to INFINITE

Posted by AKN on Stack Overflow See other posts from Stack Overflow or by AKN
Published on 2010-06-09T11:25:41Z Indexed on 2010/06/09 11:32 UTC
Read the original article Hit count: 243

Filed under:
|
|

Let say I have three thread handles

HandleList[0] = hThread1;
HandleList[1] = hThread2;
HandleList[2] = hThread3;
/*All the above are of type HANDLE*/

Before closing the application, I want the thread to get its task done. So I want to make app wait till thread completes.

So I do,

WaitForMultipleObjects(3, HandleList, TRUE, INFINITE );

By this I'm able to make the thread, complete its task. But control never move to next line after the call to WaitForMultileObjects irrespective of all thread completing its task.

If I use, some seconds instead of INFINITE, it comes to next line after that many secs, irrspective of whether thread completes its task or not.

WaitForMultipleObjects(3, HandleList, TRUE, 10000 );

My problem here is, I'm can't go for seconds, as I may not be sure whether the threads will complete its task with the given time.

To list my problem in simple words, I want all my thread to finish the task, before I close my app. How can I achieve it using WaitForMultipleObjects API?

© Stack Overflow or respective owner

Related posts about winapi

Related posts about threads