Solved

Threads

Posted on 2000-04-22
3
324 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
[X]
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
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

696 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