Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Threads

Posted on 2000-04-22
3
Medium Priority
?
329 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 300 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

610 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