<ppdoc>
<copyright>
    Copyright (c) 2001 by Addison Wesley Longman.  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/).
</copyright>
<class name="ThreadGroup" super="Object" type="class" ref="xref-000001">
<p/>
  <classname>ThreadGroup</classname> provides a means of keeping track of a number of
  threads as a group.  A <classname>Thread</classname> can belong to only one
  <classname>ThreadGroup</classname> at a time; adding a thread to a new group will
  remove it from any previous group.  
<p/>
  Newly created threads belong to the same group as the thread from
  which they were created.
  <constants>
<tr>
  <td><constant>
       <constname>Default</constname>
       <constval></constval>
       <constdesc>Default thread group.</constdesc>
     </constant>
</td>
</tr>
</constants>
<p/>
  <methods type="class">
<p/>
        <method name="new" ref="new">
      <callseq>
        ThreadGroup.new
        <returns><obj>thgrp</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns a newly created <classname>ThreadGroup</classname>.  The group is initially 
      empty.
<p/>
      </desc>
    </method>
<p/>
  </methods>
<p/>
  <methods type="instance">
<p/>
        <method name="add" ref="add">
      <callseq>
        <obj>thgrp</obj>.add( <obj>aThread</obj> )
        <returns><obj>thgrp</obj></returns>
      </callseq>
      <desc>
<p/>
            Adds the given thread to this group, removing it from any other
      group to which it may have previously belonged.
<p/>
<codefragment>
<alltt><fullcode><![CDATA[        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}"
]]></fullcode>
puts<nbsp/>"Initial<nbsp/>group<nbsp/>is<nbsp/>#{ThreadGroup::Default.list}"
tg<nbsp/>=<nbsp/>ThreadGroup.new
t1<nbsp/>=<nbsp/>Thread.new<nbsp/>{<nbsp/>sleep<nbsp/>10<nbsp/>}
t2<nbsp/>=<nbsp/>Thread.new<nbsp/>{<nbsp/>sleep<nbsp/>10<nbsp/>}
puts<nbsp/>"t1<nbsp/>is<nbsp/>#{t1}"
puts<nbsp/>"t2<nbsp/>is<nbsp/>#{t2}"
tg.add(<nbsp/>t1<nbsp/>)
puts<nbsp/>"Initial<nbsp/>group<nbsp/>now<nbsp/>#{ThreadGroup::Default.list}"
puts<nbsp/>"tg<nbsp/>group<nbsp/>now<nbsp/>#{tg.list}"
</alltt>
</codefragment>
<em>produces:</em>
<codefragment><alltt>
Initial<nbsp/>group<nbsp/>is<nbsp/>#&lt;Thread:0x401bc5c8&gt;
t1<nbsp/>is<nbsp/>#&lt;Thread:0x401b34a0&gt;
t2<nbsp/>is<nbsp/>#&lt;Thread:0x401b3450&gt;
Initial<nbsp/>group<nbsp/>now<nbsp/>#&lt;Thread:0x401b3450&gt;#&lt;Thread:0x401bc5c8&gt;
tg<nbsp/>group<nbsp/>now<nbsp/>#&lt;Thread:0x401b34a0&gt;
</alltt>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="list" ref="list">
      <callseq>
        <obj>thgrp</obj>.list
        <returns><obj>anArray</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns an array of all existing <classname>Thread</classname> objects that belong 
      to this group.
<p/>
<codefragment>
<fullcode><![CDATA[        ThreadGroup::Default.list
]]></fullcode><rubycode>
<tr>
  <td><tt>ThreadGroup::Default.list</tt></td>
  <td>&#187;</td>
  <td><tt>[#&lt;Thread:0x401bc5c8<nbsp/>run&gt;]</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
  </methods>
<p/>
</class>
</ppdoc>
