From: Eric Hodel Date: 2004-10-31T04:06:03+09:00 Subject: Re: Thread::list and GC --rJwd6BRFiFCcLxzm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Robert Klemme (bob.news@gmx.net) wrote: >=20 > "Bill Kelly" schrieb im Newsbeitrag=20 > news:015a01c4bdfc$44198d30$6442a8c0@musicbox... > >From: "Robert Klemme" > >>> > are there any issues with iterating Thread::list - since this li= st=20 > >>> > is > >>> > obviously changing all the time in this code (new Threads starte= d) > >>> > >>> Maybe, > >>> > >>> while th =3D Thread::list.find {|t| t !=3D Thread.current} > >>> begin > >>> th.join > >>> rescue =3D> e > >>> warn{ e } > >>> end > >>> end > >> > >>This does not make a difference as Thread.list() creates a new array on > >>each invokation: > >> > >>>> Thread.list().id > >>=3D> 135026036 > >>>> Thread.list().id > >>=3D> 135022100 > >>>> Thread.list().id > >>=3D> 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... >=20 > Ooops, sorry I overlooked the loop. I concetrated on the iteration with= =20 > each vs. find. >=20 > But: this solution has a problem. You can't ensure that it terminates. = =20 > You will have to set some kind of flag somewhere that no new threads are= =20 > created anyway. *If* you do that, you can just as easily wait once for a= ll=20 > currently running threads *after* the flag has been set because you know= =20 > there will be no new threads. That flag is Thread.critical =3D true It will prevent the scheduling of other threads. Note that starting a new thread can switch to that thread, so be careful. --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --rJwd6BRFiFCcLxzm Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQFBg+YXMypVHHlsnwQRAnppAKDbcMIiSQdcEYY8k9DeZUmSw+xO8QCeOP7d MFJWRpWqsvhPZdllUHraOvw= =3IXa -----END PGP SIGNATURE----- --rJwd6BRFiFCcLxzm--