Programmierung in Ruby

Der Leitfaden der Pragmatischen Programmierer

class ThreadGroup
Parent: Object
Version: 1.6

Index:

new add list


Die Klasse ThreadGroup gibt ein Mittel an die Hand, um mehrere Threads als Gruppe zu behandeln. Ein Thread-Objekt kann zu einer gegebenen Zeit nur zu einer ThreadGroup gehören; das Hinzufügen eines Threads zu einer neuen Gruppe hat automatisch die Entfernung aus einer anderen Gruppe zur Folge.

Neu erstellte Threads gehören zu derselben Gruppe wie dasjenige Thread, von dem sie erstellt wurden.
Konstanten
Default Standard Thread-Gruppe.

class methods
new ThreadGroup.new -> thgrp

Gibt eine neu erstellte ThreadGroup zurück. Die Gruppe ist anfangs leer.

instance methods
add thgrp.add( einThread ) -> thgrp

Fügt den angegebenen Thread zu der Gruppe hinzu, wobei dieser gleichzeitig aus der Gruppe, zu der er zuvor evtl. gehörte, entfernt wird.

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:0x40196528>
t1 is #<Thread:0x4018d400>
t2 is #<Thread:0x4018d3c4>
Initial group now #<Thread:0x4018d3c4>#<Thread:0x40196528>
tg group now #<Thread:0x4018d400>

list thgrp.list -> einArray

Gibt ein Array aller existierenden Thread-Objekte zurück, die zu dieser Gruppe gehören.

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


Extracted from the book "Programming Ruby - The Pragmatic Programmer's Guide"
Übersetzung: Carsten Schinzer
Für das englische Original:
© 2000 Addison Wesley Longman, Inc. Released under the terms of the Open Publication License V1.0. That reference is available for download.
Diese Lizenz sowie das Original vom Herbst 2001 bilden die Grundlage der Übersetzung
Es wird darauf hingewiesen, dass sich die Lizenz des englischen Originals inzwischen geändert hat.
Für die deutsche Übersetzung:
© 2002 Jürgen Katins
Der Copyright-Eigner stellt folgende Lizenzen zur Verfügung:
Nicht-freie Lizenz:
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.
Freie Lizenz:
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".