From: Bill Kelly Date: 2004-10-31T09:54:52+09:00 Subject: Re: Thread::list and GC From: "Robert Klemme" > > >> > while th = Thread::list.find {|t| t != Thread.current} > >> > begin > >> > th.join > >> > rescue => e > >> > warn{ e } > >> > end > >> > end > > 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. I did think about that, whether it would terminate... But I'd guessed that practically speaking the only scenario in which it wouldn't terminate is if the threads we're trying to join are themselves just spawning new threads like crazy. Kind of like a fork() bomb, but with threads... :) I thought about making it fancier with raising our own Thread priority, and/or using Thread.critical... But I was guessing that in a reasonably well-behaved system, the liklihood of the above code not terminating was pretty much nil. . . . So I was betting we wouldn't need to worry about it. Does it seem the above would be likely to not terminate outside of extreme cases like a "fork() bomb with threads" ? Regards, Bill