Solved

Threads

Posted on 2000-04-22
3
312 Views
Last Modified: 2013-11-20
I have multiple threads created in a fn, i need to wait until all the threads finish their job. How am i to do it?
0
Comment
Question by:venkateshl
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
GlennDean earned 75 total points
ID: 2740006
Hi:
   A thread handle becomes signalled when the thread terminates.  So, to wait for nCount-many threads to ALL terminate, you write
WaitForMultipleObjects(nCount,lpHandles,TRUE,INFINITE);

Here, lpHandles is a pointer to an array of thread handles.  The 3rd parameter being TRUE means to wait for all the threads to complete (if it were set to FALSE that would mean stop waiting when any one of the 3 threads completes).
   Glenn
0
 
LVL 3

Expert Comment

by:GlennDean
ID: 2740010
Hi:
   You would define the array of handles as, for example
#define nCount 5  //5 threads
HANDLE threadHandles[nCount];
....
WaitForMultipleObjects(nCount,threadHandles,TRUE,INFINITE);
   Glenn
0
 
LVL 1

Expert Comment

by:hsdhina
ID: 2741438
Hai,
  You can use the API
WaitForMultipleObjects () function
with the last parameter as INFINITE to wait until all the threads can finish their job.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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