Solved

Threads

Posted on 2000-04-22
3
301 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
viewing source code from eclipse 13 105
matchUp  challenge 9 108
Updating statistics with error notification email in SQL server 4 95
Message not shown 5 50
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: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

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