Solved

Threads

Posted on 2000-04-22
3
281 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 video discusses moving either the default database or any database to a new volume.

746 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now