From: Eric Hodel Date: 2005-01-25T02:19:25+09:00 Subject: Re: nuby threading on threads --Apple-Mail-49--569072998 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=ISO-8859-1; format=flowed On 24 Jan 2005, at 01:08, Kaspar Schiess wrote: > (In response to news:20050124005127.F2A9982B3@mx2.delmonte-phil.com by > Pe=F1a, Botp) > >> LIMIT=3D 10 >> tlist =3D [] tlist =3D ThreadGroup.new >> loop { >> if tlist.size< LIMIT >> tlist << Thread.new { p "test" } tlist.add Thread.new { p "test" } >> else >> sleep 5 >> end >> } ThreadGroups automatically drop Threads that are no longer alive. Use=20= tlist.list to get the list of threads currently in the ThreadGroup. > I'd recommend discarding threads that are dead from the list like = this: > > tlist.select! { |t| t.alive? } Threads may die between the time you pick them out and the time you=20 decide to do something with them. You'll have to check each one in a=20 critical section before doing some work that requires the thread to be=20= alive, or rescue an exception around the operation. --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --Apple-Mail-49--569072998 content-type: application/pgp-signature; x-mac-type=70674453; name=PGP.sig content-description: This is a digitally signed message part content-disposition: inline; filename=PGP.sig content-transfer-encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (Darwin) iD8DBQFB9S4KMypVHHlsnwQRAse8AJ95QijOrWUzbXk4dfAabhSaPL4dYgCghaXm C03+HHUXm2x0315/5Lpu3r0= =ZqAn -----END PGP SIGNATURE----- --Apple-Mail-49--569072998--