Don't poll for thread exit. See WaitForSingleObject(), if you only need to
wait for one thread, or WaitForMultipleObjects() if you are just going to
sit there until all of the threads exit (common in the main() routine).
The easiest way to look these functions up is to use Google (
http://www.google.com ) and just type in the function name -- Google
indexes Microsofts Dev Network better than Microsoft does... The following
link should get you started. PLEASE READ THE ENTIRE PAGE. Microsoft likes
to hide extremely important information in the "Remarks" section.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/syn
chro_4ldg.asp
That should all be on one line -- if it isn't, please reconstruct it (or
just use Google -- this was the first entry on the result page for
"waitforsingleobject" (I'm lazy and don't specify letter case in searches...).
Also, please be aware of the fact that C++ does not have ANY thread support
at all. Any threading you do will be system dependent. The closest you
can get to "C++ threads" would be the portable threading library that is
part of BOOST (http://www.boost.org). I haven't had a chance to work with
BOOST yet, but by all reports, getting yourself a good STL implementation
(like from http://www.stlport.org) and then strapping in the newest BOOST
classes gives you a really nice set of tools to work with. The C++
committe is looking seriously at BOOST for possible inclusion in the next
C++ standard, so you may want to start familiarizing yourself now. Also,
code built with the BOOST threading libraries stands the best chance of
being both cross platform portable and surviving through future standards
revisions.
(Just to avoid the response -- another "standard" threading system is POSIX
threads, or pthreads. pthreads is indeed fairly standard across UNIX-ish
OSs, but not particularly supported under Windows. The BOOST libraries are
reported to work on at least the major platforms.)
http://www.boost.org/libs/thread/doc/overview.html
Mac
At 05:37 PM 6/16/02 +0530, Abhijit Shylanath wrote:
>> do
>> {
>> GetExitCodeThread(hThread, &exit_code);
>> } while(exit_code == STILL_ACTIVE);
>> cout << "\n Thread " << i+1 << " has completed.\n";
>
>
>I almost fergot... polling GetExitCodeThread() can be very CPU intensive, so
>you might want to Sleep() in between polls, as in
>
>do
>{
> GetExitCodeThread(hThread, &exit_code);
> Sleep(DELAY);
>} while(exit_code == STILL_ACTIVE);
>
>DELAY can be 100 or more or less, I dunno, depending on the need for speed.
>
>I don't know of any synchornous method to do this.
>
-
_____________________________ /"\
Mac Reiter \ / ASCII Ribbon Campaign
Nomadics, Inc. X Against HTML Mail
re...@no... / \ (To join the campaign, simply use
this in your signature.)
|