"Bill Kelly" <billk / cts.com> schrieb im Newsbeitrag 
news:015a01c4bdfc$44198d30$6442a8c0 / musicbox...
> From: "Robert Klemme" <bob.news / gmx.net>
>> > >    are there any issues with iterating Thread::list - since this list 
>> > > is
>> > >    obviously changing all the time in this code (new Threads started)
>> >
>> > Maybe,
>> >
>> >   while th = Thread::list.find {|t| t != Thread.current}
>> >     begin
>> >       th.join
>> >     rescue => e
>> >       warn{ e }
>> >     end
>> >   end
>>
>> This does not make a difference as Thread.list() creates a new array on
>> each invokation:
>>
>> >> Thread.list().id
>> => 135026036
>> >> Thread.list().id
>> => 135022100
>> >> Thread.list().id
>> => 135018212
>
> The OP mentioned the possibility of new threads being created
> all the while.  I had read that as the OP wanting to ensure
> that we would handle the joining any new threads that may have
> become spawned while we were trying to shut down others.
> So my proposed solution was intended to loop until all threads
> were truly joined...

Ooops, sorry I overlooked the loop.  I concetrated on the iteration with 
each vs. find.

But: this solution has a problem.  You can't ensure that it terminates.  You 
will have to set some kind of flag somewhere that no new threads are created 
anyway.  *If* you do that, you can just as easily wait once for all 
currently running threads *after* the flag has been set because you know 
there will be no new threads.

Kind regards

    robert