On Sun, 25 Mar 2001 13:46:38 +0900, Joseph McDonald <joe / vpop.net>
wrote:

>
>> it blocks the rest of the program.  Why are the threads exitting
>> prematurely?
>
>Never mind... I just read that threads are automatically killed
>when the program terminates.  If I add a sleep(100) at the end
>the threads keep trying.

I'm no threads expert (having written my first UNIX pthreads program
only last week), however what I did to force the program to wait until
the threads had finished was to have the main thread, rather than
sleeping, join each of the threads it creates.

I got this idea from one of the pickaxe book's simpler examples.

I'm still looking for a way to do this, but to have the main thread
notified as each thread terminates (which could be in a different
order to that in which they were created, hence just doing a join to
each one in order isn't really good enough).

If someone can tell me how to do this in Ruby, or if that's not
supported, I'd still be interested to know how to do it using the
pthreads library under UNIX.