Ruby 1.9.2 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > ThreadGroupクラス
クラスの継承リスト: ThreadGroup < Object < Kernel < BasicObject
スレッドグループを表すクラスです。グループに属する Thread をまとめて 操作することができます。
Thread は必ずいずれかひとつのスレッドグループに属します。 生成されたばかりの Thread は、生成した Thread のグループを引き継ぎます。 メインスレッドはデフォルトでは ThreadGroup::Default に属します。
生成したすべてのThreadが終了するのを待つ
5.times { Thread.new { sleep 1; puts "#{Thread.current} finished" } } (ThreadGroup::Default.list - [Thread.current]).each {|th| th.join} puts "all threads finished"
対象の Thread が Thread を起こす可能性がある場合 (Thread.exclusive参照)
Thread.exclusive do (ThreadGroup::Default.list - [Thread.current]).each {|th| th.join} end
どちらのメソッドでも ThreadGroup#add によるスレッドの追加ができなくなる点は同じですが、 Thread.new に関して違いがあります。現在のスレッドが属する ThreadGroup が freeze されている場合、Thread.new{ ... } はエラーになります。ThreadGroup が enclose されているだけでは、 Thread.new{ ... } はエラーになりません。生成されたスレッドは従来通り 親スレッドの ThreadGroup に属します。
定義 | 説明 | |
---|---|---|
new -> ThreadGroup
|
新たな ThreadGroup を生成して返します。 |
定義 | 説明 | |
---|---|---|
add(thread) -> self
|
スレッド thread が属するグループを自身に変更します。 |
|
enclose -> self
|
自身への ThreadGroup#add によるスレッドの追加・削除を禁止します。 enclose された ThreadGroup に追加や削除を行うと例外 ThreadError が発生します。 |
|
enclosed? -> bool
|
自身が enclose されているなら true を返します。そうでないなら false を返します。デフォルトは false です。 |
|
list -> [Thread]
|
self に属するスレッドの配列を返します。 version 1.8 では、aborting 状態であるスレッド も要素に含まれます。つまり「生きている」スレッドの配列を返します。 |
定義 | 説明 | |
---|---|---|
Default -> ThreadGroup
|
デフォルトで定義されている ThreadGroup です。メインスレッド は最初このグループに属します。 |
!
!=
==
===
=~
__id__
__send__
_dump
class
clone
dclone
display
enum_for
eql?
equal?
extend
freeze
frozen?
hash
initialize
initialize_copy
inspect
instance_eval
instance_exec
instance_of?
instance_variable_defined?
instance_variable_get
instance_variable_set
instance_variables
is_a?
marshal_dump
marshal_load
method
method_missing
methods
must_be
must_be_close_to
must_be_empty
must_be_instance_of
must_be_kind_of
must_be_nil
must_be_same_as
must_be_within_epsilon
must_equal
must_include
must_match
must_raise
must_respond_to
must_send
must_throw
nil?
pretty_inspect
pretty_print
pretty_print_cycle
pretty_print_inspect
pretty_print_instance_variables
private_methods
protected_methods
public_methods
remove_instance_variable
respond_to?
respond_to_missing?
singleton_class
singleton_method_added
singleton_method_removed
singleton_method_undefined
singleton_methods
taint
tainted?
tap
to_a
to_ary
to_hash
to_int
to_io
to_proc
to_regexp
to_s
to_str
to_yaml
to_yaml_properties
to_yaml_style
trust
untaint
untrust
untrusted?
wont_be
wont_be_close_to
wont_be_empty
wont_be_instance_of
wont_be_kind_of
wont_be_nil
wont_be_same_as
wont_be_within_epsilon
wont_equal
wont_include
wont_match
wont_respond_to