File: ref_c_threadgroup.xml

package info (click to toggle)
rubybook 0.2-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,252 kB
  • ctags: 1,043
  • sloc: xml: 60,486; makefile: 25
file content (121 lines) | stat: -rw-r--r-- 3,576 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<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">
<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:0x40196528&gt;
t1<nbsp/>is<nbsp/>#&lt;Thread:0x4018d400&gt;
t2<nbsp/>is<nbsp/>#&lt;Thread:0x4018d3c4&gt;
Initial<nbsp/>group<nbsp/>now<nbsp/>#&lt;Thread:0x4018d3c4&gt;#&lt;Thread:0x40196528&gt;
tg<nbsp/>group<nbsp/>now<nbsp/>#&lt;Thread:0x4018d400&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:0x40196528<nbsp/>run&gt;]</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
  </methods>
<p/>
</class>
</ppdoc>