Programmering i Ruby

Den Pragmatiske Programmerers Veiledning

Forrige < Innhold ^
Neste >
klassen ThreadGroup
Forelder: Object
Versjon: 1.6

Indeks:

new add list


ThreadGroup provides a means of keeping track of a number of threads as a group. A Thread can belong to only one ThreadGroup at a time; adding a thread to a new group will remove it from any previous group.

Newly created threads belong to the same group as the thread from which they were created.
konstanter
Default Default thread group.

klassemetoder
new ThreadGroup.new -> thgrp

Returns a newly created ThreadGroup. The group is initially empty.

instansmetoder
add thgrp.add( aThread ) -> thgrp

Adds the given thread to this group, removing it from any other group to which it may have previously belonged.

puts "Initial group is #{ThreadGroup::Default.list}"
tg = ThreadGroup.new
t1 = Thread.new { sleep 10 }
t2 = Thread.new { sleep 10 }
puts "t1 is #{t1}"
puts "t2 is #{t2}"
tg.add( t1 )
puts "Initial group now #{ThreadGroup::Default.list}"
puts "tg group now #{tg.list}"
produces:
Initial group is #<Thread:0x401bc5c8>
t1 is #<Thread:0x401b34a0>
t2 is #<Thread:0x401b3450>
Initial group now #<Thread:0x401b3450>#<Thread:0x401bc5c8>
tg group now #<Thread:0x401b34a0>

list thgrp.list -> anArray

Returns an array of all existing Thread objects that belong to this group.

ThreadGroup::Default.list » [#<Thread:0x401bc5c8 run>]


Forrige < Innhold ^
Neste >

Extracted from the book "Programming Ruby - The Pragmatic Programmer's Guide".
Translation to norwegian by Norway Ruby User Group.
Copyright for the english original authored by David Thomas and Andrew Hunt:
Copyright © 2001 Addison Wesley Longman, Inc.
This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at
http://www.opencontent.org/openpub/).

(Please note that the license for the original has changed from the above. The above is the license of the original version that was used as a foundation for the translation efforts.)

Copyright for the norwegian translation:
Copyright © 2002 Norway Ruby User Group.
This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at
http://www.opencontent.org/openpub/).
Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder.
Distribution of the work or derivative of the work in any standard (paper) book form is prohibited unless prior permission is obtained from the copyright holder.