[210] in Pthreads mailing list archive

home help back first fref pref prev next nref lref last post

How to join multiple thread ?

daemon@ATHENA.MIT.EDU (Ryan Wong Hong Yeh)
Mon Nov 20 02:09:25 1995

From: Ryan Wong Hong Yeh <ryan@stcs.com.sg>
To: pthreads@MIT.EDU
Date: Mon, 20 Nov 1995 14:43:04 SST

Hi all,

I have a question about pthread_join(). I would like my main thread
(i.e. the one that created all the new threads) to obtain the exit 
code of the other threads..

For example: I can do this easily in NT.

main()
{
        HANDLE threads[20];

        // Create # of threads here ..
        for (int i=0; i < 20; i++) {
                threads[i] = CreateThread(...);
        }
        // This function will returns when one of the threads exit!
        WaitForMulitipleObjects(20,threads,FALSE,..);

}

How can I do the same thing in Pthread  ????  I could probably do
something like:

main()
{
        pthread_t threads[20];

        for (int i=0; i < 20; i++) {
                threads[i] = pthread_create(...);
        }

        // don't think this will work because, it is joining 
        // threads[0] and then threads[1] ....
        // what happen if threads[5] exit ? I want to know
        // immediately ...
        for (int i=0; i < 20; i++) {
                pthread_join (threads[i], status);
        }
}

Any suggestion and discussion is greately appreciated ...
Thanks..
later,
--
-Ryan            
-ryan@stcs.com.sg

home help back first fref pref prev next nref lref last post